我正在尝试编写一个程序来生成一个伪随机数并允许用户猜测它。当用户猜测数字错误时,我最希望函数返回到条件循环的开始处,而不是函数的开始部分(这会导致它产生一个新的伪随机数)。这是我到目前为止有:用Python猜数字游戏的控制循环
def guessingGame():
import random
n = random.random()
input = raw_input("Guess what integer I'm thinking of.")
if int(input) == n:
print "Correct!"
elif int(input) < n:
print "Too low."
guessingGame()
elif int(input) > n:
print "Too high."
guessingGame()
else:
print "Huh?"
guessingGame()
如何才能让伪随机数不变本地从而使错误的猜测后的数字会不会有变化?
我不知道任何可以做你想做的任何编程语言。 – 2012-01-10 01:07:11
您已将此问题标记为'loops'。所以你似乎知道答案已经是... – 2012-01-10 01:07:56
除BASIC外! GOTO赢得胜利! – 2012-01-10 01:08:34