csci 4 :: book learning challenge 9 (due wed, nov 13)

(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:

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)))
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.")
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:
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=" ")
5. Write the Python code in the box below to display the contents of the list temperatures:
temperatures = [74.8, 83.1, 77.9]
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]))
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]
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.")
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]
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]
11. Write the Python code in the box below to display the first two items from the list dinner, using slicing.
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"]
13. Write the Python code in the box below to append "truffles" to the list dessert from the question above.
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.
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.
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.