#!/usr/bin/env python def printIntroduction(): """Print introduction.""" print "This program converts Celsius to/from Fahrenheit temperature." print def celsius2Fahrenheit(): """Convert a Celsius degree to a corresponding Fahrenheit degree.""" celsius = input("What is the Celsius temperature? ") print "The temperature is", c2f(celsius), "degrees Fahrenheit." print def fahrenheit2Celsius(): """Convert a Fahrenheit degree to a corresponding Celsius degree.""" fahrenheit = input("What is the Fahrenheit temperature? ") print "The temperature is", f2c(fahrenheit), "degrees Celsius." print def printTable_c2f(): """Print Celsius degreess to Fahrenheit degrees.""" print "celsius\tfahrenheit" for celsius in range(0, 101, 20): print celsius, "\t", c2f(celsius) print def printTable_f2c(): """Print Fahrenheit degrees to Celsius degrees.""" print "fahrenheit\tcelsius" for fahrenheit in range(200, 99, -20): print fahrenheit, "\t", f2c(fahrenheit) print def printTable(): """Print Fahrenheit degrees to Celsius degrees and Fahrenheit degrees again.""" print "celsius\tfahrenheit\tcelsius" for celsius in range(0, 101, 20): print celsius, "\t", c2f(celsius), "\t", f2c(c2f(celsius)) print def c2f(celsius=0): """Convert a Celsius degree to a corresponding Fahrenheit degree. Keyword argument: celsius -- the celsius degree to convert (default 0) """ return 9.0 / 5.0 * celsius + 32; def f2c(fahrenheit=0): """Convert a Fahrenheit degree to a corresponding Celsius degree. Keyword argument: fahrenheit -- the fahrenheit degree to convert (default 0) """ return (fahrenheit - 32) * 5.0 / 9.0 if __name__ == "__main__": printIntroduction() celsius2Fahrenheit() fahrenheit2Celsius() printTable_c2f() printTable_f2c() printTable()