我试着做一个'猜猜1-10之间的数字'游戏,但while循环似乎继续运行。我想程序让用户猜测一个数字,然后显示如果它太高或太低等,然后重新开始自动(循环)允许用户再次挑选。这段代码让它永远运行。 你们能帮我吗?
import random
def numberGuess():
printNow("I'm thinking of a number between 1 and 10")
guess = 0 # give guess a starting value
randNum = random.randrange(1,11) # this line generates a random number
guess = int(input("Try to guess the number:")) # ask user for a number
print randNum
while guess != randNum:
if (guess == randNum):
print "You got it!"
if (guess > randNum):
print "Wrong! You guessed too high"
if (guess < randNum):
print "Wrong! You guessed too low"
你忘了在圈里猜
使用这个:
如果将
input
语句移到while循环中,就应该可以了。相关问题 更多 >
编程相关推荐