python - 为什么我的 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。
解决方案
它完美地工作。在解释器中不起作用可能是因为后面有两个换行符,print(10)
而 while 循环在没有输入的情况下运行。把它放在一个file.py
并运行python file.py
推荐阅读
- python - Exception has occurred: ImportError cannot import name 'Rescaling'
- python-3.x - Getting proper callback for multiple listbox
- python - Django skips a url pattern?
- bash - Running a command in a Docker container with variables
- swift - ARView 黑屏
- javascript - 已达到文件观察者数量的系统限制
- ruby - Mechanize gem 是否支持 TLS 1.2 以及如何设置它?
- python - 如何从 ctypes.Structure 取回原始缓冲区?
- save - 我应该在编程时启用自动保存吗?
- angular - Angular 8 - 在迭代之前等待承诺在循环中完成