CSC111 Lab 4 Solution Programs
--D. Thiebaut 10:03, 29 September 2011 (EDT)
# Solution snipets for Lab 4
for c in "abcdefghijklmnopqrstuvwxyz":
print( "a" + c )
print()
for first in "ab":
for second in "abcdefghijklmnopqrstuvwxyz":
print( first + second )
print()
for first in "abc":
for second in "abcdefghijklmnopqrstuvwxyz":
print( first + second )
print()
for first in "abc":
for second in "abcdefghijklmnopqrstuvwxyz":
print( "111a-" + first + second )
print( "\nmini challenge\n" )
for second in "abcdefghijklmnopqrstuvwxyz":
for first in "abc":
print( first + second, end=' ' ) #quote space quote
print()
print( "\nChallenge #2\n" )
zoo = [ "pig", "horse", "elephant" ]
count = 1
for animal in zoo:
for i in range( count ):
print( animal, end=" " ) # that's a space between quotes
print()
count = count + 1
print( "\nChallenge #3\n" )
semesters = [ "sprint", "fall" ]
years = [ "2010", "2011", "2012", "2013" ]
for year in years:
for sem in semesters:
print( sem, year )
# or
print()
semesters = [ "sprint", "fall" ]
years = [ 2010, 2011, 2012, 2013 ]
for year in years:
for sem in semesters:
print( sem, year )
# or
print()
semesters = [ "sprint", "fall" ]
for year in range( 2010, 2014):
for sem in semesters:
print( sem, year )
print( "\n\n Challenge #4\n\n" )
for i in range( 1,10 ):
for j in range( 1, 10 ):
print( i*j, sep=" ", end=" " ) # no space between the double quotes
print()
for i in range( 1,10 ):
for j in range( 1,i+1 ):
print( "%3d" % (i*j), sep=" ", end=" " ) # no space between the double quotes
print()