我做了简单的python函数,它接受两个输入并输出一些文本。
这里是,
def weather():
israining_str=input("Is it raining (1 or 0) ? ")
israining = bool(israining_str)
temp_str=input("What is the temp ? ")
temp = float(temp_str)
if israining==True and temp<18:
return "Umbrella & Sweater"
elif israining==True and temp>=18:
return "Umbrella"
elif israining==False and temp<18:
return "Sweater"
else:
return "Cap"
测试数据 -
>>>
Is it raining ? 0
What is the temp ? 43
Umbrella
>>> ================================ RESTART ================================
>>>
Is it raining ? 1
What is the temp ? 43
Umbrella
>>>
如果下雨是假的,它会覆盖Sweater
或Cap
。但是我的代码甚至给出了 trueisraining_str == 0
或israining_str == 1
我在哪里做错了?