你的朋友要出国去美国旅行,所以他写了一个程序来将华氏度转换为摄氏度。不幸的是,他的代码有一些错误。
找出代码中的错误,让摄氏度转换器正常工作。
将华氏度转换为摄氏度。
摄氏度 = (华氏 - 32) * (5/9)
请记住,通常当前天气条件下的温度是以整数给出的。温度传感器有可能以更高的精度报告温度,
例如精确到最近的十分之一。但仪器误差使得这种精度对许多类型的温度测量传感器来说都不可靠。
# 请仔细看代码并更正
def weather_info(temp):
c: convert(temp)
if (c > 0):
return (c + " is freezing temperature")
else:
return (c + " is above freezing temperature")
def convertToCelsius(temperature):
var
celsius = (temperature) - 32 + (5 / 9)
return temperature
变量、函数、字符串、函数传参数
def weather_info (temp):
c = convertToCelsius(temp)
if (c <= 0):
return (str(c) + " is freezing temperature")
else:
return (str(c) + " is above freezing temperature")
def convertToCelsius (temperature):
celsius = (temperature - 32) * (5.0/9.0)
return celsius