Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def windchill(T,V):
- """
- A function that computes the windchill factor using temperature and windspeed.
- >>> windchill(5,10)
- -9.737344294197483
- >>> windchill(20,20)
- 4.242781599820461
- >>> windchill(-10,50)
- -45.32064601872968
- """
- wc_factor = (35.74 + 0.6215 * T - 35.75 * V**0.16 + 0.4275 * T * V**0.16) #formula for windchill
- return(wc_factor)
- def main():
- try:
- while True:
- # asks the user for a windspeed start value, if the value is negative it
- # will re-ask until value is positive
- while True:
- wind_start = int(input("Windspeed start value?: "))
- if wind_start < 0:
- print("Windspeed can't be negative!")
- else:
- break
- # asks the user for a windspeed endvalue, if the value is negative it
- # will re-ask until value is positive
- while True:
- wind_stop = int(input("Windspeed stop value?: "))
- if wind_stop < 0:
- print("Windspeed can't be negative!")
- else:
- break
- #asks for windspeed increment value
- wind_increment = int(input("Windspeed increment value?: "))
- print ("")
- # asks for all temperature values
- t_start = int(input("Temperature start value?: "))
- t_stop = int(input("Temperature stop value?: "))
- t_increment = int(input("Temperature increment value?: "))
- print("")
- print("")
- # prints header of table-- first line; prints temperature heading
- # and all windspeed values
- vel = " T(degF)"
- for V in range(wind_start, wind_stop, wind_increment):
- velocity = str(V) + " mph"
- vel = vel + " {0:>7s}".format(velocity)
- print(vel)
- # prints a divider
- spacer = ""
- for i in range(wind_start, (wind_stop + 1), wind_increment):
- spacer = spacer + " {0:7s}".format("=======")
- print(spacer)
- # prints temperature and each row of windchill index for the temperature
- for T in range(t_start, t_stop, t_increment):
- temperature = " {0:7d}".format(T)
- for V in range(wind_start, wind_stop, wind_increment):
- temperature = str(temperature) + " {0:7.2f}".format(round(windchill(T,V), 2))
- print(temperature)
- # lets user quit program if they press ENTER
- leave = str(input("Press ENTER to quit: "))
- if leave == "":
- break
- else:
- continue
- except:
- # checks if user input for windspeed/temperature are number values
- print("That's not a valid number, try again.")
- if __name__ == "__main__":
- import doctest
- doctest.testmod()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement