@@ -0,0 +1,1937 @@
+# Chapter 11 Practice Questions%0A%0A# 1. What does the following code print?%0Aspam = %7B'name': 'Al'%7D%0Aprint(spam%5B'name'%5D)%0A%0A# 2. What does this code print?%0Aspam = %7B'eggs': 'bacon'%7D%0Aprint('bacon' in spam)%0A%0A# 3. What for loop code would print the values in the following spam%0A#    dictionary?%0Aspam = %7B'name': 'Zophie', 'species': 'cat', 'age': 8%7D%0A%0Afor key in spam:%0A    print(spam%5Bkey%5D)%0A%0A# 4. What does the following line print?%0Aprint('Hello, world!'.split())%0A%0A%0A# 5. What will the following code print?%0Adef spam(eggs=42):%0A    print(eggs)%0A%0A%0Aspam()%0Aspam('Hello')%0A%0A# 6. What percentage of words in this sentence are valid English words?%0Asentence = %22Whether it's flobulllar in the mind to quarfalog the slings and arrows of outrageous guuuuuuuuur.%22%0A%0A%0AUPPERLETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'%0ALETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS.lower() + ' %5Ct%5Cn'%0A%0A%0Adef loadDictionary():%0A    dictionaryFile = open('dictionary.txt')%0A    englishWords = %7B%7D%0A    for word in dictionaryFile.read().split('%5Cn'):%0A        englishWords%5Bword%5D = None%0A    dictionaryFile.close()%0A    return englishWords%0A%0A%0AENGLISH_WORDS = loadDictionary()%0A#  Not in dictionary. Too small?%0AENGLISH_WORDS%5B'IN'%5D = None%0AENGLISH_WORDS%5B'TO'%5D = None%0AENGLISH_WORDS%5B'OF'%5D = None%0A%0A%0Adef getEnglishCount(message):%0A    message = message.upper()%0A    message = removeNonLetters(message)%0A    possibleWords = message.split()%0A%0A    if not possibleWords:  # Given %5B%5D = False, if possibleWords = %5B%5D then if not possibleWords = True%0A        return 0.0  # No words at all, so return 0.0%0A%0A    matches = 0%0A    for word in possibleWords:%0A        if word in ENGLISH_WORDS:%0A            matches += 1%0A    print(matches, possibleWords)%0A    return float(matches) / len(possibleWords)%0A%0A%0Adef removeNonLetters(message):%0A    lettersOnly = %5B%5D%0A    for symbol in message:%0A        if symbol in LETTERS_AND_SPACE:%0A            lettersOnly.append(symbol)%0A    return ''.join(lettersOnly)%0A%0A%0Aprint(getEnglishCount(sentence) * 100)%0A

Initialize PracticeQuestions