小编Joh*_*aus的帖子

while循环在python中有多个条件

weatherType = raw_input('Enter a weather type: ')

while (weatherType != "WINDDIRECTION") or (weatherType != "WINDSPEED") or (weatherType != "AIRTEMPERATURE") or (weatherType != "WAVEHEIGHT") or (weatherType != "AIRPRESSURE"):
    print "Sorry, invalid input. Please enter AIRTEMPERATURE, AIRPRESSURE, WAVEHEIGHT, WINDSPEED, or WINDDIRECTION  for a city and either WINDDIRECTION, WINDSPEED, or AIRTEMPERATURE for an off shore bouy"
    weatherType = raw_input('Enter a weather type: ')
Run Code Online (Sandbox Code Playgroud)

好了,所以用这个循环中,我试图让用户输入要么WINDDIRECTION,WINDSPEED,AIRTEMPERATURE,WAVEHEIGHT,或AIRPRESSURE.但是,即使用户输入这5个选项中的1个,我的代码仍然会进入while循环.我不知道发生了什么事.我知道我可以使用for循环(对于["WINDDIRECTION",....]中的x)但是for循环只能查看他们的输入是否是第一次是正确的,如果他们再输入错误的答案代码将继续

python while-loop multiple-conditions

-1
推荐指数
1
解决办法
1591
查看次数

标签 统计

multiple-conditions ×1

python ×1

while-loop ×1