CSC111 lab5 Solutions

From dftwiki3
Revision as of 15:10, 25 February 2010 by Thiebaut (talk | contribs) (Recipes)
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()

Taxi Cab

Here is Megan's Taxi Cab:

.

# taxi.py                                                                                                             
# 111c-au                                                                                                             
# Megan Caska                                                                                                         

from graphics import *

def main():
    win = GraphWin( "Taxi", 800,600)
    rect = Rectangle(Point (225, 250), Point(575, 350))
    rect.setFill('yellow')
    rect.draw(win)
    rect2 = Rectangle(Point (300, 175), Point (500, 250))
    rect2.setFill('yellow')
    rect2.draw(win)
    rect3 =(390, 240))
    rect3.setFill('white')
    rect3.draw(win)
    rect4 =(490, 240))
    rect4.setFill('white')
    rect4.draw(win)
    center = Point(400, 300)
    label = Text (center, "TAXI")
    label.draw(win)
    ccenter1 = Point(300, 350)
    ccenter2 = Point(500, 350)    
    wheel1 = Circle(ccenter1, 50)
    wheel1.setFill('black')
    wheel1.draw(win)
    wheel2 = Circle(ccenter2, 50)
    wheel2.setFill('black')
    wheel2.draw(win)
    raw_input( "Press Enter to continue..." )
    win.close()

main()

.