Difference between revisions of "CSC111 lab5 Solutions"

From dftwiki3
Jump to: navigation, search
(Recipes)
(Taxi Cab)
Line 117: Line 117:
 
# 111c-au                                                                                                             
 
# 111c-au                                                                                                             
 
# Megan Caska                                                                                                         
 
# Megan Caska                                                                                                         
 
+
# Edited by D. Thiebaut
 +
#
 
from graphics import *
 
from graphics import *
 
+
 
def main():
 
def main():
 
     win = GraphWin( "Taxi", 800,600)
 
     win = GraphWin( "Taxi", 800,600)
 +
 +
    # body of car
 
     rect = Rectangle(Point (225, 250), Point(575, 350))
 
     rect = Rectangle(Point (225, 250), Point(575, 350))
 
     rect.setFill('yellow')
 
     rect.setFill('yellow')
 
     rect.draw(win)
 
     rect.draw(win)
 +
 +
    # top of car
 
     rect2 = Rectangle(Point (300, 175), Point (500, 250))
 
     rect2 = Rectangle(Point (300, 175), Point (500, 250))
 
     rect2.setFill('yellow')
 
     rect2.setFill('yellow')
 
     rect2.draw(win)
 
     rect2.draw(win)
     rect3 =(390, 240))
+
 
 +
    # left window
 +
     rect3 =Rectangle(Point(310, 180), Point( 390, 240 ) )
 
     rect3.setFill('white')
 
     rect3.setFill('white')
 
     rect3.draw(win)
 
     rect3.draw(win)
     rect4 =(490, 240))
+
 
 +
    # right window
 +
     rect4 =Rectangle( Point(410, 180), Point( 492, 242) )
 
     rect4.setFill('white')
 
     rect4.setFill('white')
 
     rect4.draw(win)
 
     rect4.draw(win)
 
     center = Point(400, 300)
 
     center = Point(400, 300)
 +
 +
    # label in middle of body of car
 
     label = Text (center, "TAXI")
 
     label = Text (center, "TAXI")
 
     label.draw(win)
 
     label.draw(win)
 +
 +
    # wheels
 
     ccenter1 = Point(300, 350)
 
     ccenter1 = Point(300, 350)
 
     ccenter2 = Point(500, 350)     
 
     ccenter2 = Point(500, 350)     
Line 145: Line 158:
 
     wheel2.setFill('black')
 
     wheel2.setFill('black')
 
     wheel2.draw(win)
 
     wheel2.draw(win)
 +
 +
    # keep window up until user presses Enter key
 
     raw_input( "Press Enter to continue..." )
 
     raw_input( "Press Enter to continue..." )
 
     win.close()
 
     win.close()
 
+
 
main()
 
main()
 +
  
 
.
 
.

Revision as of 16:35, 25 February 2010


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                                                                                                         
# Edited by D. Thiebaut
#
from graphics import *
 
def main():
    win = GraphWin( "Taxi", 800,600)

    # body of car
    rect = Rectangle(Point (225, 250), Point(575, 350))
    rect.setFill('yellow')
    rect.draw(win)

    # top of car 
    rect2 = Rectangle(Point (300, 175), Point (500, 250))
    rect2.setFill('yellow')
    rect2.draw(win)

    # left window
    rect3 =Rectangle(Point(310, 180), Point( 390, 240 ) )
    rect3.setFill('white')
    rect3.draw(win)

    # right window
    rect4 =Rectangle( Point(410, 180), Point( 492, 242) )
    rect4.setFill('white')
    rect4.draw(win)
    center = Point(400, 300)

    # label in middle of body of car
    label = Text (center, "TAXI")
    label.draw(win)

    # wheels
    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)

    # keep window up until user presses Enter key
    raw_input( "Press Enter to continue..." )
    win.close()
 
main()
 

.