python猜猜我是几,我在python中猜数游戏的问题

这篇博客内容是一位新手编程者尝试编写一个数字猜谜游戏的过程。游戏中,计算机随机生成1到10之间的数字,用户有3次机会猜测。如果猜测次数用完或者猜对了,程序会询问用户是否想要再玩一次。代码中包含了错误检查和游戏重玩的逻辑,但目前存在一些问题导致游戏无法正常运行。
摘要由CSDN通过智能技术生成

我是新手,所以请原谅下面的混乱…我正试图写一个数字猜谜游戏。计算机应该随机生成一个介于1到10之间的数字。用户只允许3次尝试正确猜测数字。一个用户要么猜对了,要么尝试完了,我应该让程序问用户,如果他们想再次玩,游戏应该重新启动。下面是我想到的。我想我让这件事变得复杂得多…我做错什么了,因为它不起作用?在import random

number = random.randint(1,10)

print "The computer will generate a random number between 1 and 10. Try to guess the number!"

guess = int(raw_input("Guess a number: "))

attempts = 0

while guess != number and attempts < 4:

if guess >= 1 and guess <= 10:

print "Sorry, you are wrong."

else:

print "That is not an integer between 1 and 10 (inclusive)."

guess = int(raw_input("Guess another number: "))

attempts = attempts + 1

if attempts > 4:

print "You've guessed incorrectly and are out of tries..."

playAgain = raw_input("Would you like to play again? ")

if playAgain = "Yes" or playAgain == "y":

import random

number = random.randint(1,10)

attempts = 0

guess = int(raw_input("Guess a number: "))

while guess != number and attempts < 4:

if guess >= 1 and guess <= 10:

print "Sorry, you are wrong."

else:

print "That is not an interger between 1 and 10 (inclusive)."

guess = int(raw_input("Guess another number: "))

attempts = attempts + 1

while guess == number:

print "Congratulations, you guessed correctly!"

playAgain = raw_input("Would you like to play again? ")

if playAgain = "Yes" or playAgain == "y":

import random

number = random.randint(1,10)

attempts = 0

guess = int(raw_input("Guess a number: "))

while guess != number and attempts < 4:

if guess >= 1 and guess <= 10:

print "Sorry, you are wrong."

else:

print "That is not an interger between 1 and 10 (inclusive)."

guess = int(raw_input("Guess another number: "))

attempts = attempts + 1

if attempts > 3:

print "You've guessed incorrectly and are out of tries..."

playAgain = raw_input("Would you like to play again? ")

if playAgain == "yes" or playAgain == "Yes":

import random

number = random.randint(1,10)

attempts = 0

guess = int(raw_input("Guess a number: "))

while guess != number and attempts < 4:

if guess >= 1 and guess <= 10:

print "Sorry, you are wrong."

else:

print "That is not an interger between 1 and 10 (inclusive)."

guess = int(raw_input("Guess another number: "))

attempts = attempts + 1

if attempts > 3:

print "You've guessed incorrectly and are out of tries..."

playAgain = raw_input("Would you like to play again? ")

if playAgain == "yes" or playAgain == "Yes":

import random

number = random.randint(1,10)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值