新人初学python两天,在编写一个最基础的猜数字小游戏时遇到问题。
from random import randint num = randint (1,200) print ('Guess what I think.') bingo = False while bingo == False: answer = int(input()) if answer < num: print ('%d too small' % int(input())) if answer > num: print ('%d too big' % int(input())) if answer == num: print ('Bingo!\n%d is right.' % int(input())) bingo == True
主要问题在于当Run起来的时候,程序会在第一次输入数字时没有反应,第二次输入才会给出回答。我试过了%s,%d,以及+号,但却都会出现慢一拍的情况。
而在完全相同的代码没有使用%时却可以立刻得到回答,请问这是怎么回事?
Each input() will ask you to enter a number. Your three if judgments all require a new input. You should use a variable answer to save the input variable value like the one above. The next three if judgments use this Just save the value