python - 我的代码(一个 python 猜谜游戏)继续返回“你猜到了很高”,即使我输入了 9,即该范围内的最大值
问题描述
我认为问题是即使输入了正确的数字,循环也没有结束。但是,这条线(while choice != a :)
应该可以防止这种情况发生,所以我不确定出了什么问题。
import random
a = random.randint(1, 9)
choice = int(input("give me a number"))
while choice != a :
if choice > a:
choice = int(input("You guessed too high. Please guess again"))
elif choice < a:
choice = int(input("You guessed to low. Please guess again"))
print("You won")
解决方案
推荐阅读
- c# - 预先初始化属性未知的嵌套成员
- reactjs - tinymce 所见即所得编辑器 - 文本光标问题,文本字段/区域变为非活动状态
- r - ggplot2:使用条形图和 stat = 'identity' 时 y 轴上的值不正确
- node.js - 发布请求适用于我的本地计算机,但不适用于远程服务器
- python - 您可以从 codeigniter 控制器中的函数执行 Python 脚本吗
- c - realloc 行为的可移植性
- android - 处理点击动态创建布局android的子布局
- mysql - 如何解决 CREATE TABLE 上的错误“外键约束格式错误”
- python-3.x - python找到前N个加权边缘而不考虑权重
- .net-core - 自包含的单文件 Win Form 应用程序不运行