python - 如何重新启动包含在函数中的代码?
问题描述
我想在用户输入给定的“是”后从头开始重新启动我的 python 代码,但我不明白我在这里做错了什么:
if input("Other questions? ") == 'yes' or 'yeah':
main()
else:
pass
我的代码包含在函数 main() 中。谢谢您的帮助!!
解决方案
你可能会在你想要重复的整个事情上使用一个 while 循环来做到这一点,正如 Loic RW 在评论中所说,只需跳出 while 循环:
while True:
# do whatever you want
# at the end, you ask your question:
if input("Other questions? ") in ['yes','yeah']:
# this will loop around again
pass
else:
# this will break out of the while loop
break
推荐阅读
- http - 为什么对视频服务器的第一次请求没有返回视频的字节数据
- tensorflow - 使用 flow_from_directory 在 Keras 中进行多任务输出的 ImageDataGenerator
- excel - 如何在此代码中转到下一行(结果表)?垂直到水平转置
- reactjs - 只设置一次状态
- sql - Oracle SQL - 选择不按预期使用索引
- java - 如何修复“java.io.InvalidClassExcept 本地类不兼容”错误?
- php - 使用 php 在 google sheet 上附加数据适用于本地主机,但不适用于 Cpanel
- r - 将表情符号与R中的文本结合起来
- firebase - 当我使用服务帐户执行 kreait / firebase-php 操作时,为什么 firebase 规则不起作用?
- javascript - 仅验证 URL 字符串开头的“http://”或“https://”