# Quiz #2 Solutions # September 25, 2012 # The code blocks were worth 2 points apiece. # 1a The successive values of j are 1, 3, 5, 7, 9 (but not 11) # so the totals that are printed will be # 1 4 9 16 25 # 1b We print a pair of asterisks twice for each of the three lines # * * * * # * * * * # * * * * # 1c The tricky part here was remember to tab over before the first I # and to start a new line before `cheezburger' # I can has # cheezburger? # 1d This block divides 10 by 2 repeatedly until we reach 1 # 5 2 1 # 1e These lines check the numbers from 1 to 19 and prints all those # that are a multiple of 4 or are more than 17 # 4 8 12 16 18 19 # 2 (3 points) The corrected code appears below. print "\n\t Convert inches to feet" print "\n\t inches \t feet" for j in range(0,61,6): print "\t", j, "\t", j/12.0 # 3 (7 points) One program appears below. Variations are possible, as usual. guess = raw_input("What is the capital of South Dakota? ") tries = 1 while guess != "pierre" and guess != "Pierre": print "Nope, I think that's actually a province of China." guess = raw_input("Try again: ") tries = tries + 1 print "At last! You got it in only", tries, "attempts."