Practice Problems

Lecture 3

Answer each number in a separate cell

Rename this notebook with your last name and the lecture e.g. Cych_03

Turn-in this notebook on triton-ed by the end of class

Oceans and Continents

  1. Conceptual
    • Give an example of when you would use a set
    • Give an example of when you would use a tuple
    • Give an example of when you would use range()
  2. Lists
    • Create an empty list called oceans
    • append all the oceans to the list
    • print the ocean at index 3 in the list
    • print the last element of your list.
    • make a shallow copy of oceans called seas and a deep copy of oceans called _bigwater. Try to modify the copies. Verify that the shallow copy refers to the same underlying object while the deep copy makes an independent object.
    • Apply the method .sort() to one of your copies and then print the copy
  3. range()
    • Use the function range( ) to create a list with a “range” of numbers from 0 up to (but not including) 100, increment by any number (less than 100) and print the results.
  4. Tuples
    • Create a tuple called continents with the continents as elements.
    • Attempt to change the second element (not index) in place (this should throw and error).
    • print out the third element (not index) in the tuple
  5. Sets
    • create a set from the oceans list you created earlier.
    • print out the set of oceans
In [ ]: