# someFunctions.py Define a few sample functions in Python # P. Conrad for CS5nm, 10/01/2008 # CtoF: number -> number # consumes: a temperature in Celsius # produces: a temperature in Fahrenheit import math; def CtoF(cTemp): return (cTemp / 5.0) * 9 + 32 # squared: number -> number # consumes: a number x # returns: the square of that number def square(x): return x * x def printSquare(x): print x * x def distance(x1,y1,x2,y2): return math.sqrt( square(x2-x1) + square(y2-y1) ) def check_expect(check,expect): if (check == expect): print "Test Passed" else: print "Test Failed" check_expect(square(5),25) check_expect(square(3),9) check_expect(square(-3),9) check_expect(square(0.5),0.25) check_expect(square(0),0)