这个Python代码用于猜测1到100之间的数字。'guesser()'函数没有任何问题,我知道因为我的程序也有一个完美的“手动模式”。出于某种原因,它总是将“猜测”值分配给“低”,并一直这样做,直到它等于100和程序“Ragequits”。它永远不会对“高”做任何事情,它在整个执行过程中保持默认状态。无论如何,它永远不会执行“获胜”区块。 注意:变量'high'和'low'分别从101和0开始,'guesser()'在它们之间选择一个数字。代码中较早使用'goOn'来确定此人是否想再玩一次。
num = raw_input('Enter the number which you want the computer to guess. ')
unguessed = True
while unguessed:
if high == low + 1 or high <= low:
print 'Waitafligginflagginminnit! You CHEATED! *Ragequits*'
goOn = False
unguessed = False
print ''
raw_input('Press Enter to continue.')
guesses = guesses + 1
guesss = guesser()
print 'I guessed', guesss
if guesss == num:
print 'Yay! I won in', guesses, 'guesses!'
again = raw_input('Just press enter if you want to play again. Otherwise...you know the drill. ')
unguessed = False
print '\n\n'
if again:
goOn = False
else:
print 'Awww...'
if guesss > num:
high = guesss
elif guesss < num:
low = guesss