Wind Chill计算器和定义中的数学公式

时间:2015-12-07 07:14:53

标签: python python-3.x definition

这应该是我得到的最后一个错误

velocity = wind_speed * 0.16
TypeError: can't multiply sequence by non-int of type 'float'

任何想法?我确实需要将输入定义为浮点数,抱歉,我还是python的新手。

def calc_wind_chill(f_temp, wind_speed):
    """ float, float -> float
    returns wind_chill_temperature (F)
    given farenheit temperature and
    wind_speed in miles per hour
    """
    velocity = wind_speed * 0.16
    chill = 35.74 + (0.6215 * f_temp)-(35.75 * velocity) +(0.4275 * f_temp * velocity)

    return chill
#end def



while True:
    question=input("w for windchill or q for quit: " )
    if question=="w":
        temperature=input("Air tempature in Fahrenheit: ")
        wind=input("What is the windspeed in mph: ")
        calc_wind_chill(temperature, wind)
        print("Wind Chill", chill, " F", temperature, "F ", "wind speed:", wind)
        wind_chill_2= calc_wind_chill(temperature, wind +10)
        print("wind Chill:", wind_chill_2, " F", temperature, "F  ", "wind speed:", wind + 10)

    elif question=="q":
        print("have a nice day!")
        break

1 个答案:

答案 0 :(得分:2)

函数内部的所有内容,包括注释,都需要缩进...

def calc_wind_chill(f_temp, wind_speed):
    """ float, float -> float
    returns wind_chill_temperature (F)
    given farenheit temperature and
    wind_speed in miles per hour
    """
    velocity = wind_speed ** 0.16
    chill = 35.74 + (0.6215 * f_temp)-(35.75 * velocity) +(0.4275 * f_temp * velocity)

    return chill