【发布时间】:2018-02-14 03:41:43
【问题描述】:
`
is_summer = True
print("Values 1-12 correlate to the months of the year")
while is_summer == True:
_month = int(input("Enter the month of the year: "))
if _month == 4 or 5 or 6 or 7 or 8:
is_summer = int(input("It is summer, what is the temperature?: "))
if is_summer in range(60,101):
print("The squirrels are playing")
else:
print("The squirells are not playing")
elif _month == 1 or 2 or 3 or 9 or 10 or 11 or 12:
is_summer = int(input("It is winter, what is the temperature?: "))
if is_summer in range(60,91):
print("The squirrels are playing")
else:
print("The squirrels are not playing")
`
如果我输入 1、2、3、9、10、11 或 12,我的代码将不会进入 elif 语句。是我的嵌套 if 语句执行不正确,还是其他原因?
【问题讨论】:
-
更优雅的解决方案是使用
in运算符。