Advertisement
nikhil_joshi

Sample Windchill

May 24th, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. # windchill
  2.  
  3. def windchill(t, v):
  4.     """
  5.    windchill(t,v) takes a temperature and wind speed and returns the
  6.    windchill factor.
  7.  
  8.    t = temperature in Farhenheit
  9.    v = wind speed in miles per hour
  10.  
  11.    >>> windchill(5,10)
  12.    -9.737344294197483
  13.    >>> windchill(20,20)
  14.    4.242781599820461
  15.    >>> windchill(-10,50)
  16.    -45.32064601872968
  17.    """
  18.     return 35.74 + 0.6215 * t - 35.75 * v**0.16 + 0.4275 * t * v**0.16
  19.  
  20. def getuservalue(s):
  21.     while True:
  22.         try:
  23.             val = int(input(s))
  24.             return val
  25.         except ValueError:
  26.             print("Error! - Please enter an integer.")
  27.        
  28.  
  29. def main():
  30.     tmin = getuservalue('Starting temperature in degrees Fahrenheit: ')
  31.     tmax = getuservalue('Ending temperature: ')
  32.     tinc = getuservalue('Increment value for temperature: ')
  33.  
  34.     vmin = getuservalue('\nStarting wind speed in miles per hour: ')
  35.     vmax = getuservalue('Ending wind speed: ')
  36.     vinc = getuservalue('Increment value for wind speed: ')
  37.  
  38.     print('\n\n')
  39.  
  40.     # output column header
  41.     print("T(degF)", end="")
  42.     for v in range(vmin, vmax+vinc,vinc):  
  43.         print("{:4d} mph".format(v),end="")
  44.  
  45.     print("\n=======\t",end="")
  46.     for v in range(vmin, vmax+vinc,vinc):
  47.         print("=======\t",end="")
  48.  
  49.     # print the table
  50.     print()
  51.     for t in range(tmin, tmax+tinc, tinc):
  52.         print("{:-6d}".format(t),end="|")
  53.         for v in range(vmin, vmax+vinc, vinc):
  54.             print("\t{:-7.2f}".format(windchill(t,v)),end="")
  55.         print()
  56.    
  57.     temp = input('[press ENTER to quit]')
  58.    
  59.    
  60. if __name__ == "__main__":
  61.     import doctest
  62.     doctest.testmod()
  63.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement