# Quiz #3 Solutions # October 23, 2012 # The code blocks were worth 2 points apiece. # 1a The letters in positions 3 to 7 are "repti", while the last letter # is "s", and the entire word has 13 letters. So the answer is # reptiles house # 1b This basically puts an asterisk before each character and spaces # out the characters, giving # * B * o * * P * e * e * p # 1c j takes on values 1, 3, 5, 7 so the letters in those positions are # h, s, a, c. The letters are each in front of the previous, then # made uppercase, leading to the result # CASH # 1d There are two instances of the character "g" in the string, so # 2 # 1e There is no "a" nor "z", so the first if statement doesn't execute. # There are also no "m" nor "n", so the second if statement does. # has lost her sheep. # 2 (3 points) The corrected code appears below. color = raw_input("Enter your favorite color: ") spaced = "" for letter in word: spaced = spaced + letter + " " print "Your spaced out word is", spaced + "." # 3 (7 points) One program appears below. Variations are possible, as usual. word = raw_input("Enter a word of your choice: ") word = word.strip() word = word.lower() count = 0 for j in range(0,len(word)-1): if word[j] == word[j+1]: count = count + 1 print "There were", count, "pairs of double letters in your word."