【发布时间】:2018-11-13 17:40:30
【问题描述】:
我已经尝试了所有方法,如果您不选择“ST”,它会不断循环 while 循环。我不知道该怎么做,如果有人能告诉我,那将非常有帮助。我在顶部添加了一些上下文的代码;我只需要 while 循环的帮助。我正在使用while 循环,所以如果他们没有选择给定的位置,他们必须重新选择。
这是我的代码:
pos = input("What Is Your Choice")
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and
"Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
【问题讨论】:
-
and运算符比较逻辑语句而不是值本身。试试while pos != "ST" and pos != "MID" ...: -
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}: -
也可以使用
in操作符:while pos not in ["ST", "MID", ...]
标签: python python-3.x logical-operators