csci 4 :: book learning challenge 9 (due wed, nov 13)
Submitting your work: Complete this exercise on your own.

(1) Fill in all of the "Answer" boxes, (2) press "Prepare for printing", then (3) print the answer grid.

Staple all pages together and submit to the instructor on the date listed above.

Questions:

Read Zelle 11.1-11.2 and answer the following:

Your name:
  1. What is the output of the following Python code?
    test_scores = [90, 97, 93, 98, 88]

    print("You have {0} scores.".format(len(test_scores)))
    Answer:
  2. What is the output of the following Python code?
    test_scores = []

    if len(test_scores) > 0:
         print("You have {0} scores.".format(len(test_scores)))
    else:
         print("No test scores.")
    Answer:
  3. Write the Python code in the box below to display the number of items in the list eightball_answers, using the list len function:
    eightball_answers = ["yes", "no", "maybe"]
    Answer:
  4. What is the output of the following Python code?
    items_found = ["key", "coin", "feather"]

    print("Items found:")
    for item in items_found:
         print(item, end=" ")
    Answer:
  5. Write the Python code in the box below to display the contents of the list temperatures:
    temperatures = [74.8, 83.1, 77.9]
    Answer:
  6. What is the output of the following Python code?
    favorite_authors = ["Melville", "Hemingway", "Card"]

    print("Favorite authors:")
    for i in range(len(favorite_authors)):
         print("{0}. {1}".format(i, favorite_authors[i]))
    Answer:
  7. Write the Python code in the box below to display the contents of the list primes, each with its sequential index number (for example, "0: 3" (0 being the index number for the value 3 in the list primes):
    primes = [3, 5, 7, 11, 13]
    Answer:
  8. What is the output of the following Python code?
    favorite_colors = ["red", "blue", "green", "magenta"]

    if "magenta" in favorite_colors:
         print("You like magenta too?")
    else:
         print("You should try magenta. It is a nice color.")
    Answer:
  9. Write the Python code in the box below to test for the presence of the value 42 in the list numbers. Write your code so that if 42 is present, it will display "You have the answer.", otherwise it will display "Keep looking for the answer."
    numbers = [99, 0, 70, -1, 43, 45]
    Answer:
  10. Write the Python code in the box below to display the value 42 from the list numbers using indexing.
    numbers = [99, 0, 70, -1, 42, 45]
    Answer:
  11. Write the Python code in the box below to display the first two items from the list dinner, using slicing.
    dinner = ["bread", "milk", "salad", "okra", "fish"]
    Answer:
  12. Write the Python code in the box below to display the last three items from the list dessert, using slicing.
    dessert = ["ice cream", "cake", "cookies", "fruit"]
    Answer:
  13. Write the Python code in the box below to append "truffles" to the list dessert from the question above.
    Answer:
  14. Write the Python code in the box below to (1) sort the list dessert from the questions above and then (2) print the list.
    Answer:
  15. Write the Python code in the box below to (1) reverse the list dessert from the questions above and then (2) print the list.
    Answer:
  16. Write the Python code in the box below to insert the value "pastry" into the list dessert from the questions above, as the first item in the list.
    Answer:
  17. Write the Python code in the box below to (1) retrieve the index of the value "cake" from the list dessert from the questions above, and then (2) print out the message "The cake is at index X" (replace X with the index value retrieved).
    Answer:
  18. Write the Python code in the box below to delete the first element from the list stuff. You can assume stuff has contents, but it should not matter that you cannot see what those contents are.
    Answer:
  19. Write the Python code in the box below to (1) test for the presence of "mouse" in the list kitchen and then (2) remove "mouse" from kitchen (if there is a "mouse", assume there is at most one "mouse").
    Answer:
  20. Write the Python code in the box below to remove every occurrence of "okra" from the list good_food. NOTE: it is intentional that you are not being shown what the list good_food looks like -- you must develop an algorithm that works no matter what good_good contains at any moment (it may contain no "okra", or one "okra", or two or more "okra").
    Answer:

Total points for this book learning challenge:

200 points