# bettertemp.py # Walker M. White (wmw2) # September 6, 2012 """Conversion functions between fahrentheit and centrigrade This module has been extended from the version in the previous lecture to include application code that shows off the functions. In addition, it shows the prefered way to construct an application: using a main() function.""" # Functions def to_centigrade(x): """Returns: x converted to centigrade Value returned has type float. Precondition: x is a float measuring temperature in fahrenheit""" return 5*(x-32)/9.0 def to_fahrenheit(x): """Returns: x converted to fahrenheit Value returned has type float. Precondition: x is a float measuring temperature in centigrade""" return 9*x/5.0+32 # Constants FREEZING_C = 0.0 # Temperature water freezes in centrigrade FREEZING_F = to_fahrenheit(FREEZING_C) BOILING_C = 100.0 # Temperature water freezes in centrigrade BOILING_F = to_fahrenheit(BOILING_C) def main(): """Procedure containing application code""" print 'Provide a temperature in Fahrenheit:' f = raw_input() # read from user as string f = float(f) # convert to float c = round(to_centigrade(f),2) print 'The temperature is '+`c`+' C' # Application code if __name__ == '__main__': main()