python - 为什么它说响应没有定义,即使它是
问题描述
它一直告诉我响应没有定义。
while response not in Yes or No:
response = input("Would you like to shut down the program?\nyes/no\n")
if response == "Yes":
print("Goodbye.\n")
elif response == "No":
print("Ok.")
quit()
else:
print("I didn't understand that.\n")
解决方案
假设在您提供的代码上方没有引用它,则第一次通过循环时,response
未定义。只有在第一次调用到input()
. 您需要在循环之前进行初始化。类似的东西response = None
就足够了。
推荐阅读
- c# - 动态改变 TargetName DoubleAnimation c# xaml
- node.js - tsconfig 中的路径无法导入类型
- database - MongoDB 聚合具有各个日期范围的子字段
- python - Python:删除标准差小于 25% 的列
- python - 将数据库值转换为表单时出错
- git - 在团队基础服务器上打开文件时出现“不正确的功能”错误
- python - 使用 Django 和 SMTP 协议发送电子邮件时出现 TimeoutError 错误
- python - 为什么 sqlite 3 停止在我的代码中处理“删除”类调用?
- jenkins - Jenkins 中的 CloudBees Docker Hub/注册表通知插件错误
- windows - 如何防止在 JavaFX TableView 中拖放列时触发事件