首页 > 解决方案 > 为什么我的 Python 脚本不提示用户输入?

问题描述

我是一个完全的菜鸟,但为什么我的 python 代码没有在 Python 3.7.3 windows 命令行中提示用户输入?

user_wants_number = True
while user_wants_number == True:
    print(10)

    user_input = input("Should we print again? (y/n)")
    if user_input == 'n':
        user_wants_number = False

...
user_wants_number = True
while user_wants_number == True:
    print(10)

    user_input = input("Should we print again? (y/n)")
    if user_input == 'n':
        user_wants_number = False
...

我希望输出显示“我们应该再次打印吗?” 对我来说是或否,循环会做出相应的响应。但是,它只是继续打印数字 10。

标签: pythonpython-3.x

解决方案


它完美地工作。在解释器中不起作用可能是因为后面有两个换行符,print(10)而 while 循环在没有输入的情况下运行。把它放在一个file.py并运行python file.py


推荐阅读