def WindChill(T, W): """Returns the windchill factor as a rounded float value. Fahrenheit temperature input will return result in Fahrenheit. Celsius temperature input will return result in Celsius. Precondition: T is a string that represents temperature, numbers without a unit specification will be assumed as in units of Fharenheit. W is a string that represents windspeed, numbers without a unit specification will be assumed as in units of miles per hour.""" if 'F' in T: #temperature in Fharenheit pt = T.find('F') #finding position of 'F' in user input temp = float(T[:pt]) #extract numerical values of temperature elif 'C' in T: #temperature in Celsius pt = T.find('C') #finding position of C in user inputs num = float(T[:pt]) #extract numerical values temp = Weather.to_F(num) #converting Celsius to Fharenheit elif T.find('F') == -1 and T.find('C') == -1: #user input without units temp = float(T) if 'mph' in W: #for wind speed in miles per hour pw = W.find('mph') #position of 'mph' in user input wind = float(W[:pw]) #extract numerical values of windspeed elif 'kph' in W: #for wind speed in kilometers per hour pw = W.find('kph') #position of 'kph' in user input windink = float( W[:pw] ) #extract numerical values of windspeed in kilometers per hour wind = Weather.to_M(windink) #convert kilometers to miles else: #for windspeed inputs without unit specification, assumes it's in miles wind = float(W) #convert string value into float if 'C' in T: #user inputs temperature in Celsius if temp <= 50.0: TrueWCF = float( round(Weather.to_C(Weather.WCF(temp, wind))) ) #celsius input will return windchill factor in celsius if wind <= 3.0: #if wind is smaller than 3mph return num #returns temperature in Celsius if 'C' in T and wind <= 3.0: return TrueWCF elif 'C' in T and temp > 50.0: return num elif temp >= 50.0 or wind <= 3.0: #when temp is greater than 50F or the wind speed is less than 3mph, Fahrenheit windchill temp equals air temp. TrueWCF = float(round(temp)) else: TrueWCF = float( round(Weather.WCF(temp, wind)) ) #otherwise, windchill factor will be calculated and returned as a rounded float value. return TrueWCF
def WindChill(T,W): """ Place an informative doc string here in the required style. """ # Develop the function body here... # Code for Temperature # temperature in Celcius # temperature in Fahrenheit if 'F' in T: temp=int(T[:T.find('F')]) elif 'C' in T: tempC=int(T[:T.find('C')]) # temperature into Fahrenheit temp=Weather.to_F(tempC) # temperature without a unit else: temp=int(T) # Code for Wind Speed # speed in kph if 'mph' in W: wind=int(W[:W.find('mph')]) elif 'kph' in W: windK=int(W[:W.find('kph')]) wind=Weather.to_M(windK) # speed in mph # speed without a unit else: wind=int(W) if 'C' in T: if temp<=50.0: TrueWindchill=float(round(Weather.to_C(Weather.WCF(temp, wind)))) elif wind>=3.0: TrueWindchill=float(round(Weather.to_C(Weather.WCF(temp, wind)))) elif temp>50.0 or wind<3.0: TrueWindchill=float(round(tempC)) elif temp>50.0 or wind<3.0: TrueWindchill=float(round(temp)) else: TrueWindchill=float(round(Weather.WCF(temp, wind))) return TrueWindchill