CSC111 Lab 6 Solutions 2014

From dftwiki3
Revision as of 16:43, 6 March 2014 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut (talk) 18:47, 3 March 2014 (EST)


Solution Programs

# CSC111
# solution program for Lab 6
#

# Challenge 1
"""
# start with four animals in the farm
farm = [ "horse", "pig", "dog", "cat" ]

# sing(): a function that simulates singing a refrain for the song
# using the animal name.     
def sing( word ):
     print( "And on his farm he had a %s, E-I-E-I-O" % word )

# "sing" all the names of the animals
for animal in farm:
     sing( animal )
"""

# Challenge 2
"""
# start with four animals in the farm
farm = [ "horse", "pig", "dog", "cat" ]

# sing(): a function that simulates singing a refrain for the song
# using the animal name.     
def sing( word ):
    print( "Old MacDonald had a farm, E-I-E-I-O" )
    print( "And on his farm he had a %s, E-I-E-I-O" % word )
    print( "Here a %s, there a %s, everywhere a %s!" % ( word, word, word ) )
    print()
    
# "sing" all the names of the animals
for animal in farm:
     sing( animal )
"""

# Challenge 3
"""
# start with four animals in the farm
farm = [ "horse", "pig", "dog", "cat" ]

# sing(): a function that simulates singing a refrain for the song
# using the animal name.     
def sing( word ):
    print( "Old MacDonald had a farm, E-I-E-I-O" )
    print( "And on his farm he had a %s, E-I-E-I-O" % word )
    print( "Here a %s, there a %s, everywhere a %s!" % ( word, word, word ) )
    print()

def singSong( animal1, animal2, animal3, animal4 ):
     sing( animal1 )
     sing( animal2 )
     sing( animal3 )
     sing( animal4 )
     
# "sing" all the names of the animals
singSong( "horse", "pig", "dog", "cat" )
"""

# Disney Dwarves
"""
seven = [ "Sleepy", "Sneezy", "Bashful", "Happy", "Grumpy", "Dopey", "Doc" ]

def box( string ):
    line = "+"  +  ("-"*len( string ) )  + "+" 
    print( line )
    print( "|" + string + "|" )
    print( line )
    print()

for dwarf in seven:
    box( dwarf )
"""

# Game and Minion
def student1( sentence ):
    print( sentence.upper() )

def student2( sentence ):
    print( sentence.lower() )

def student3( s1, s2 ):
    student1( "shhhhhhhh!" )
    student1( s1 )
    student2( s2 )
    student2( "thank you" )

student3( "Welcome", "to CSC111 Lab 6!" )

# Challenge 4
"""
def printBlock( visible ):
    if visible==True:
        print( "#", end="" )
    else:
        print( ".", end="" )

def printLine( visibility ):
    printBlock( visibility )
    printBlock( not visibility )
    printBlock( visibility )
    printBlock( not visibility )
    printBlock( visibility )
    printBlock( not visibility )
    printBlock( visibility )
    printBlock( not visibility )
    print()

printLine( True )
printLine( False )
printLine( True )
printLine( False )
printLine( True )
printLine( False )
printLine( True )
printLine( False )
"""

# Challenge 5
"""
def printBlock2( visible ):
    if visible==True:
        print( "#", end="" )
    else:
        print( ".", end="" )

def printLine( visibility ):
    for i in range( 8 ):
        printBlock2( visibility )
        visibility = not visibility
    print()

firstBlack = True
for i in range( 8 ):
    printLine( firstBlack )
    firstBlack = not firstBlack 
"""