Difference between revisions of "CSC111 lab5 Solutions"

From dftwiki3
Jump to: navigation, search
(Created page with ' <onlydft> ==Recipes== <source lang="python"> # recipe.py # def separatorLine(): print 30 * '-' + 'oOo' + 30 * '-' def printLines( recipe ): separatorLine() f…')
 
Line 1: Line 1:
  
 +
<onlydft>
 +
 +
==Stick Figure==
 +
<source lang="python">
 +
 +
# 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()
 +
 +
</source>
 +
 +
==Birthday==
 +
 +
<source lang="python">
 +
# 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"
  
<onlydft>
+
def main():
 +
    singSong( "Alex" )
 +
 
 +
    for ch in 'abcdefghijklmnopqrstuvwxyz':
 +
        singSong( "111c-a" + ch )
 +
 
 +
main()
 +
 
 +
</source>
  
 
==Recipes==
 
==Recipes==

Revision as of 13:06, 24 February 2010


...