MATH 385 Week 03 Worksheet

  1. Calculate 252^5 by typing this mathematical expression in the code cell below and then execute the cell and the entire notebook by clicking Rumtime > Run all.
  2. Create new variable that holds a list that stores one of each of the following types: int, float, string, bool, and list. Make up the variable names.
  3. Create a new variable that holds a dictionary that stores at least three made up pets. The keys of the dict should be a pet name and the values should be the type of pet. In this case, both keys and values are strings.
  4. Create a list that holds a 5 pet dicts as elements. Each pet dict should have keys name, age, species.
  5. Write a function that accepts a string and returns the same string with all letters capitalized.
  6. Write a function that accepts a list of strings and returns a list of the input strings with all characters capitalized. Call the function appropriately.
  7. Write a function count_unique(lst) that counts the unique elements of list argument lst. The output should be a dictionary with unique elements as keys and counts as the values. For example, count_unique([1, 1, 2, 2, 2, 3]) should return {1: 2, 2: 3, 3: 1}. Call the function appropriately.
  8. Write a function collatz_inner(n) that accepts a positive integer greater than 1 and returns
    • half of n if n is even, or
    • three times n plus one if n is odd.
    Call the function appropriately.
  9. Write a function collatz(n) that accepts a positive integer greater than 1 and returns of a list of evaluations of collatz_inner(n) until n is less than 1. The last element of the returned list should be 1. For example, collatz(2) should return [1], and collatz(17) should return [52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]. Call the function appropriately.
  10. Write a class Pet that stores as internal/private members/properties the animal type, name, and age. The class should have getters that return the animal's species, name, and age. There should be a method speak that returns what your animal says as a string. The variables species, name, age, and the string of what your animal says should all be arguments to the constructor. There should also be a method collatz_name that returns the collatz(...) number of the length of the name of your Pet.
  11. Write a function collatz_pets(lst_pets) that takes a list of Pets and prints calls of the method collatz_name for each pet.
  12. Call the function from 11. on a list of Pets.