在函数选项完成后,while 循环仍然继续,即使 update 与它需要的字符串之一相同。满足更新条件后如何停止while循环while update.lower() != "tests" or "lessons" or "adjust": update = input("Do you want to update content from 'lessons' or 'tests'. Or do you want to 'adjust' what you aren't confident with. respond with 'adjust' 'lesson' or 'tests'").lower() if update.lower() == "tests" or "lessons" or "adjust": options()
2 回答

临摹微笑
TA贡献1982条经验 获得超2个赞
你需要
while update.lower() not in ["tests", "lessons", "adjust"]
你写的内容被解析为
{update.lower() != "tests"} OR {"lessons"} OR {"adjust"}
(括号只是为了显示语言如何对术语进行分组)
由非空字符串组成的条件在python中始终为真,因此“课程”部分将始终为真,while
循环永远不会。

狐的传说
TA贡献1804条经验 获得超3个赞
就是因为or你觉得他们的工作,在你的榜样,他们被解释为不同条件下在你的代码不能正常工作update.lower() != "tests",lessons并且adjust因此近两年一直在为处理True所以这个循环将永远不会结束。相反,你应该这样做:
while update.lower() not in ["tests", "lessons", "adjust"]:
update = input("Do you want to update content from 'lessons' or 'tests'. Or do you want to 'adjust' what you aren't confident with. respond with 'adjust' 'lesson' or 'tests'").lower()
if update.lower() in ["tests", "lessons", "adjust"]:
options()
添加回答
举报
0/150
提交
取消