# CS106 Python Function Examples def f1(x): return x * 10 def f2(x,y): print x + y def f3(x,y): if x > y: print "x is greater than y" else: if y > x: print "y is greater than x" else: print "x and y are equal" def f4(x,y): while x < y: x = x + 4 y = y - 2 print "x = ", x print "y = ", y def power(x,y): # returns x to the power y; y must be >= 0 total = 1 while y > 0: total = total * x y = y - 1 return total def power2(x,y): # returns x to the power y; y must be >= 0 total = 1 for z in range(1,y+1): total = total * x return total def sumLoop(first,last): # returns the sum of the integers from first to last sum = 0 for x in range(first,last+1): sum = sum + x return sum def average(list): sum = 0.0 count = 0 for x in list: sum = sum + x count = count + 1 return sum/count def largest(list): biggestSoFar = list[0] for x in list: if (x > biggestSoFar): biggestSoFar = x return biggestSoFar def nestedLoop(first,last): for x in range(first,last+1): for y in range(1, x+1): print y, " " , print "\n"