# Introduction to Computing
# CS110, Fall 2009
# Professor Blank
# Practice Sheet #2: Answers

# 1a. A prime number is a number that is only evenly divisible by
# itself and 1. Write a Python function that determines whether or not
# a number is prime.

def isPrime(number):
    for i in range(number):
        if (i > 1) and (number % i == 0):
            return False
    return True

# 1b. Write a function that takes a list of words that are, in this
# order: a noun phrase, a place, an animal with determiner, another
# animal with determiner, another place, a body part, a property of a
# person. The function should use the words to write a limerick. For
# example:

def limerick(list):
    print "There once was " + list[0] +  " from " + list[1]
    print "Who told " + list[2] + " joke to a " + list[3]
    print "Under " + list[4] +", his " + list[5] + " lies"
    print "because the " + list[3] + " had no " + list[6]


>>> limerick(["a man", "yuma", "an elephant", "puma", 
              "hot western skies", "skeleton", "sense of humor"])
There once was a man from yuma
Who told an elephant joke to a puma
Under hot western skies, his skeleton lies
because the puma had no sense of humor

>>> limerick(["a hippy", "Manilla", "a fart", "noseless Gorilla", 
              "a pile of tie-dyes", "dread lock", "way to smella"])
There once was a hippy from Manilla
Who told a fart joke to a noseless Gorilla
Under a pile of tie-dyes, his dread lock lies
because the noseless Gorilla had no way to smella

# 4. What does the following mystery function do?

def mystery(a, b, c):
    return (a + b + c) / 3.0

>>> mystery(1, 2, 3)
2.0

# 5. Write two functions that will make your robot dance and call them.

def boogie(seconds):
    forward(1, seconds)
    backward(1, seconds)

def woogie(seconds):
    turnLeft(1, seconds)
    turnRight(1, seconds)

boogie(1)
woogie(.5)
woogie(1)
boogie(.5)
boogie(2)
woogie(.5)
woogie(.5)
boogie(.1)
