CSC111 lab5 Solutions

From dftwiki3
Revision as of 14:48, 25 February 2010 by Thiebaut (talk | contribs)
Jump to: navigation, search


Stick Figure

# newstick.py
# Draws sticks on the screen
 
def head():
    print
    print "   o     "
 
def body():
    print "  /|\\   "
 
def legs():
    print " _/ \\_  "
    print
 
def roundBody():
    print "  /O\\    " 
 
def longLegs():
    print "  / \\   "
    print "_/   \\_ "
    print
 
def skinnyStickFigure():
    head();
    body();
    legs();
 
def roundLongFigure():
    head();
    roundBody()
    longLegs()

def main():
    skinnyStickFigure()
    roundLongFigure()
main()

Birthday

# happyBirthday.py
# D. Thiebaut

def hbday():
    print "Happy birthday to you!"

def dear( name ):
    print "Happy birthday, Dear", name

def singSong( name ):
    for i in range( 3 ):
        hbday()
    dear( name )
    hbday()
    print "\n\n"

def main():
    singSong( "Alex" )

    for ch in 'abcdefghijklmnopqrstuvwxyz':
        singSong( "111c-a" + ch )

main()

Recipes

# recipe.py
# 

def separatorLine():
     print  30 * '-' + 'oOo' + 30 * '-'

def printLines( recipe ):
    separatorLine()
    for line in recipe[0:1]:
        print line
    separatorLine()
    for line in recipe[1:]:
        print line
    separatorLine()
    print "\n\n"

def main():
    recipe1 = ["Smoked Salmon Tortellini with Bechamel Sauce",
               "2 packages tortellini",
               "1 bay leaf",
               "2 whole cloves",
               "1 pinch nutmeg",
               "1 chopped red bell pepper",
               "1/2 lb fresh asparagus",
               "10 ounces fresh mushrooms" ]
    recipe2 = [ "Bechamel Sauce", "1/4 cup butter", "2 tbsp flour", "1/4 cup milk"]

    printLines( recipe1 )
    printLines( recipe2 )

main()