Solution
From wiki.ucalgary.ca
def calculate():
aCircle = areaCircle(3) aSquare = areaSquare(3) aRectangle = areaRectangle(3,4) print "Circle: ", aCircle print "Square: ", aSquare print "Rectangle: ", aRectangle
def areaCircle(r):
area = pi * r * r return area
def areaSquare(a):
area = a*a return area
def areaRectangle(a,b):
area = a*b return area
def fibonacci(n):
prev1 = 0 prev2 = 1 for i in range(1,n+1): if i == 1: print "1 ", else: fib = prev1 + prev2 print fib, " ", prev1 = prev2 prev2 = fib print ""
def draw(width, height):
for w in range(0,height): for h in range(0,width): print "*", print ""
def prime(n):
isprime = true for i in range(1,n+1): if (i != 1 and i != n) or n == 1: if n%i == 0: isprime = false if isprime: print "Prime" else: print "Not Prime"