必须编写一些代码来定义一个可以使用两个或三个参数的函数。
该函数应采用三个参数:
如果温度低于冰点(如果 is_celsius 为 False,则为 32,如果 is_celsius 为 True,则该函数应返回 True)或天气“下雪”。否则,它应该返回 False。
但是请注意, is_celsius 应该是一个可选参数。如果函数调用没有为 is_celsius 提供值,则假定它为 True。
我写了这个
def snowed_in(temperature, weather, **cels):
if weather =="snowy":
return True
elif weather=="sunny":
if 'is_celsius = False' in cels:
if temperature<32:
return True
elif 'is_celsius = True' in cels:
if temperature<0:
print ('ad')
return True
elif 'is_celsius = True' not in cels:
if temperature<0:
return True
else:
return False
Run Code Online (Sandbox Code Playgroud)
以及以下电话
print(snowed_in(15, "sunny")) #Should print False
print(snowed_in(15, "sunny",is_celsius = False)) #Should …Run Code Online (Sandbox Code Playgroud)