Python‎ > ‎Python Mini Projects‎ > ‎Study Guides‎ > ‎

02 Windchill Study Guide

Study Guide

For the test you should understand the syntax for the following concepts and commands, and how they are typically used:

  • print, print "\n", print "\t"
  • "hanging commas", the effect a comma has at the end of a print statement
  • range([init,] end [, inc]), the output of a range command and the roles that the first, second, and third number play.
  • for-loops and indented code blocks
  • nested for-loops to generate tables and other 2-dimensional data


Sample Code


# 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(raw_input(s))
            return val
        except ValueError:
            print "Error! - Please enter an integer."
        

def main():
    tmin = getuservalue('Please enter starting temperature in degrees Fahrenheit: ')
    tmax = getuservalue('Please enter ending temperature: ')
    tinc = getuservalue('Please enter an increment value for temperature: ')

    vmin = getuservalue('\nPlease enter a starting wind speed in miles per hour: ')
    vmax = getuservalue('Please enter an ending wind speed: ')
    vinc = getuservalue('Please enter an increment value for wind speed: ')

    # Build a windchill lookup table
    print('\n\n')

    # output column header
    print "T(degF)\t",
    for v in range(vmin, vmax+vinc,vinc):   # adding increment to the max value to
        print v,"mph\t",                    # ensure we output the max value or greater

    print "\n======\t",
    for v in range(vmin, vmax+vinc,vinc):
        print "======\t",

    # print the table
    print
    for t in range(tmin, tmax+tinc, tinc):
        print t,
        for v in range(vmin, vmax+vinc, vinc):
            print "\t%-4.2f"%(windchill(t,v)),
        print
    
    temp = raw_input('[press ENTER to quit]')
    
    
if __name__ == "__main__":
    import doctest
    doctest.testmod()
    main()