python - python - 循环中断不会第二次工作
问题描述
def play_again():
again = input("would you like to play another game? ").lower()
while play_again:
if again == "yes":
play_again()
elif again == "no":
print("thank you for playing with us")
break
else:
again = input("only yes, or no answers are allowed: ").lower()
continue
play_again()
如果我运行代码并输入 no,代码将退出。
如果我运行代码并输入yes
,代码继续,但如果第二个输入是no
,代码将不会退出:(
有人能帮我吗?
解决方案
感谢那些回答的人,我删除了while循环并选择了一种现在可以使用的不同方式:
def play_again():
again = input("would you like to play another game? ").lower()
if again == "yes":
play_again()
elif again == "no":
print("thank you for playing with us")
else:
print("only yes, or no answers are allowed")
play_again()
play_again()
推荐阅读
- jboss7.x - Drools 无法解析记录器
- java - Spring Boot Test MalformedURLException:未知协议:类路径
- ruby-on-rails - 在 Windows 上安装 Rails gem 时出错
- javascript - 如何替换附加到另一个字符串的字符串?
- ios - 动量滚动错误 iOS
- algorithm - 动态规划,第 n 个字符串
- mysql - 如何在“User::with”查询中使用 eloquent 获取 Laravel 中的某些列?
- javascript - 在我的 NodeJS 应用程序的评论部分添加文本格式
- crystal-reports - 可以使详细信息部分充当页脚吗?
- flask - 多对多,带有额外字段 flask-admin sqlalchemy