我正在为一个猜谜游戏编写一个代码,在这个游戏中,用户可以为要输入的数字选择一个范围,程序将选择一个随机数,用户可以猜到数字,直到他们是正确的
我试过使用条件和while循环,但无法运行它
if (userGuess > targetNum):
print "\nToo high\n"
elif (userGuess < targetNum):
print "\nToo low\n"
else:
print "\nThat's it! Nice job!\n"
这个程序运行,但我需要帮助让它循环,以便用户可以输入他们的猜测,并得到反馈,如果它太高或太低,直到他们猜测正确的数字。谢谢
应该将IF语句放在
while True:
循环中添加将由条件触发的布尔值
你需要确保在你成功的时候打破循环
输出可能看起来像
相关问题 更多 >
编程相关推荐