Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # windchill
- def windchill(t, v):
- """
- windchill(t,v) takes a temperature and wind speed and returns the
- windchill factor.
- t = temperature in Farhenheit
- v = wind speed in miles per hour
- >>> windchill(5,10)
- -9.737344294197483
- >>> windchill(20,20)
- 4.242781599820461
- >>> windchill(-10,50)
- -45.32064601872968
- """
- return 35.74 + 0.6215 * t - 35.75 * v**0.16 + 0.4275 * t * v**0.16
- def getuservalue(s):
- while True:
- try:
- val = int(input(s))
- return val
- except ValueError:
- print("Error! - Please enter an integer.")
- def main():
- tmin = getuservalue('Starting temperature in degrees Fahrenheit: ')
- tmax = getuservalue('Ending temperature: ')
- tinc = getuservalue('Increment value for temperature: ')
- vmin = getuservalue('\nStarting wind speed in miles per hour: ')
- vmax = getuservalue('Ending wind speed: ')
- vinc = getuservalue('Increment value for wind speed: ')
- print('\n\n')
- # output column header
- print("T(degF)", end="")
- for v in range(vmin, vmax+vinc,vinc):
- print("{:4d} mph".format(v),end="")
- print("\n=======\t",end="")
- for v in range(vmin, vmax+vinc,vinc):
- print("=======\t",end="")
- # print the table
- print()
- for t in range(tmin, tmax+tinc, tinc):
- print("{:-6d}".format(t),end="|")
- for v in range(vmin, vmax+vinc, vinc):
- print("\t{:-7.2f}".format(windchill(t,v)),end="")
- print()
- temp = input('[press ENTER to quit]')
- if __name__ == "__main__":
- import doctest
- doctest.testmod()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement