[英]Python: why isn't my if statement running
I've been trying to write basic settings for my code and for some reason my if statement isn't working.我一直在尝试为我的代码编写基本设置,但由于某种原因,我的 if 语句不起作用。 I am pretty sure that my mistake is really stupid, but I can't find it.
我很确定我的错误真的很愚蠢,但我找不到它。
elif menu == 3:
set1 = 3
print("1.Restart the program automatically")
print("2.Restart the program manually")
while set1 != 1 or set1 != 2:
set1 == int(input("Please enter your choice:"))
if set1 == 1:
print("Set 1 works")
elif set1 == 2:
print("Set 2 works")
else:
print("Smash the monitor")
print("Goes to the main body")
there are two mistakes you need to fix.您需要修复两个错误。
while set1:= 1 or set1 != 2:
to while set1:= 1 and set1 != 2:
otherwise it will never stop.while set1:= 1 or set1 != 2:
更改为while set1:= 1 and set1 != 2:
否则它将永远不会停止。set1 == int(input("Please enter your choice:"))
to set1 = int(input("Please enter your choice:"))
set1 == int(input("Please enter your choice:"))
更改为set1 = int(input("Please enter your choice:"))
now everything is Ok.现在一切正常。 final code must look like this:
最终代码必须如下所示:
elif menu == 3:
set1 = 3
print("1.Restart the program automatically")
print("2.Restart the program manually")
while set1 != 1 and set1 != 2:
set1 = int(input("Please enter your choice:"))
if set1 == 1:
print("Set 1 works")
elif set1 == 2:
print("Set 2 works")
else:
print("Smash the monitor")
print("Goes to the main body")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.