python - Break Program while in a while true - try and except
问题描述
如果用户输入“否”,我需要我的程序中断。此时程序不会中断,当输入'no'时,try and except 重新启动
while final_answer_check == True:
try:
final_answer = str(input("Do you want a copy of the answers?"))
if final_answer.lower() == "no":
final_answer_check = False
我希望程序会中断,但它只是问“你想要答案的副本吗?” 再次
解决方案
首先,您需要定义变量final_answer_check
并将值设置为True
. 如果你在一个块中构建你的代码try...except
,你需要让它完整,而不仅仅是try
.
final_answer_check = True
while final_answer_check == True:
try:
final_answer = str(input("Do you want a copy of the answers?"))
if final_answer.lower() == "no":
final_answer_check = False
else:
final_answer_check = True
except:
print ("your another code should be here")
推荐阅读
- ios - 在 Swift 中导航“返回”时,AVPlayer 视频消失
- python - SSH 跳转服务器,使用授权码作为第二步验证
- python - Django base.models.Post.DoesNotExist
- html - 在特定屏幕宽度上居中子 div
- sql - 在 vb.net 中编译 executebal 时如何将数据部署到 %programdata% 目录
- compilation - APKtool FAIL - 没有创建 apk
- java - 如何在 Akka Typed 中使用 AskPattern.ask?(Java/科特林)
- python - 按外观分配编号,然后按iD cumsum
- javascript - 有没有办法覆盖事件对象并做我喜欢的事情?
- sql - Hive 串联