我是一个初学者程序员,我创造了一个猜谜游戏,但我想纳入一个字符串,将打印时,用户按回车键,我已经尝试了这个,但它不起作用。(当用户按enter键时,返回错误“ValueError:invalid literal for int(),以10为基数)。你知道吗
如果用户不按enter键,只输入整数,程序就可以正常工作。你知道吗
highest = 12
lowest = 6
answer = 9
input("Press enter to play a guessing game")
guess = input("Guess a number from %d " %lowest + "to %d: " %highest)
while (int(guess) != answer) or guess == ():
if int(guess) > answer:
print ("Answer is lower")
elif guess == ():
print ("That's not valid")
else:
print("Answer is higher")
guess = input("Guess again ")
print ("Correct!!")
相关问题 更多 >
编程相关推荐