Advertisement
mka43435

Untitled

May 24th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. def windchill(T,V):
  2.     """
  3.   A function that computes the windchill factor using temperature and windspeed.
  4.  
  5.   >>> windchill(5,10)
  6.   -9.737344294197483
  7.   >>> windchill(20,20)
  8.   4.242781599820461
  9.   >>> windchill(-10,50)
  10.   -45.32064601872968
  11.   """
  12.     wc_factor = (35.74 + 0.6215 * T - 35.75 * V**0.16 + 0.4275 * T * V**0.16) #formula for windchill
  13.     return(wc_factor)
  14.  
  15. def main():
  16.         try:
  17.                 while True:
  18.                         # asks the user for a windspeed start value, if the value is negative it
  19.                         # will re-ask until value is positive
  20.                         while True:
  21.                                 wind_start = int(input("Windspeed start value?: "))
  22.                                 if wind_start < 0:
  23.                                         print("Windspeed can't be negative!")
  24.                                 else:
  25.                                         break
  26.                         # asks the user for a windspeed endvalue, if the value is negative it
  27.                         # will re-ask until value is positive
  28.                         while True:
  29.                                 wind_stop = int(input("Windspeed stop value?: "))
  30.                                 if wind_stop < 0:
  31.                                         print("Windspeed can't be negative!")
  32.                                 else:
  33.                                         break
  34.                         #asks for windspeed increment value
  35.                         wind_increment = int(input("Windspeed increment value?: "))
  36.                         print ("")
  37.  
  38.                         # asks for all temperature values
  39.                         t_start = int(input("Temperature start value?: "))
  40.                         t_stop = int(input("Temperature stop value?: "))
  41.                         t_increment = int(input("Temperature increment value?: "))
  42.                         print("")
  43.  
  44.                         print("")
  45.  
  46.                         # prints header of table-- first line; prints temperature heading
  47.                         # and all windspeed values
  48.                         vel = " T(degF)"
  49.                         for V in range(wind_start, wind_stop, wind_increment):
  50.                                 velocity = str(V) + " mph"
  51.                                 vel = vel + " {0:>7s}".format(velocity)
  52.                         print(vel)
  53.                        
  54.                         # prints a divider
  55.                         spacer = ""
  56.                         for i in range(wind_start, (wind_stop + 1), wind_increment):
  57.                                 spacer = spacer + " {0:7s}".format("=======")
  58.                         print(spacer)
  59.  
  60.                         # prints temperature and each row of windchill index for the temperature
  61.                         for T in range(t_start, t_stop, t_increment):
  62.                                 temperature = " {0:7d}".format(T)
  63.                                 for V in range(wind_start, wind_stop, wind_increment):
  64.                                         temperature = str(temperature) + " {0:7.2f}".format(round(windchill(T,V), 2))
  65.                                 print(temperature)
  66.  
  67.                         # lets user quit program if they press ENTER
  68.                         leave = str(input("Press ENTER to quit: "))
  69.                         if leave == "":
  70.                                 break
  71.                         else:
  72.                                 continue
  73.  
  74.         except:
  75.                 # checks if user input for windspeed/temperature are number values
  76.                 print("That's not a valid number, try again.")
  77.  
  78. if __name__ == "__main__":
  79.     import doctest
  80.     doctest.testmod()
  81.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement