Homework 7

Enter your name and EID here

This homework is due on Mar. 26, 2019 at 4:00pm. Please submit as a PDF file on Canvas. Before submission, please re-run all cells by clicking "Kernel" and selecting "Restart & Run All."

Problem 1 (5 pts): Create a list with the names of your favorite animals. Your list should contain at least 5 animals. Then, complete the following steps using python. Each step should be completed in a different cell and your results should be printed with print().

  1. Sort the list so that the names appear in alphabetical order.
  2. Print how many items there are in the list. Hint: use the function len().
  3. Remove an animal from your list and print the length of the list again.
  4. Add the animal "ostrich" to your list.
  5. Make a new list in which every animal name in your original list is repeated 3 times.

Problem 2 (5 pts): Now imagine that you have gone to the zoo to see your favorite animals listed in Problem 1. Create a dictionary that contains the names of the animals as keys and counts for each animal as the values. (For example, if there are 3 giraffes at the zoo, the key would be "giraffe" and the value would be 3.) The counts should just be made-up counts. Then, complete the following steps using python. Each step should be completed in a different cell and your results should be printed with print().

  1. Write code that counts how many animals total you observed. (In other words, add up all of the animal counts.)
  2. Add an animal "monkey" to your dictionary and give it a count of 5.
  3. Print out a list of the keys and a list of the values in your dictionary (i.e., the animal names and the counts).
  4. Change the count for one of the animals in your dictionary (i.e., monkey's count 5 to 8).
  5. Remove a key-value pair from your dictionary.