Practice Problems¶

Lecture 4¶

Answer each number in a separate cell

Rename this notebook with your last name and the lecture

ex. CychB_04



Turn-in this notebook on TritonEd by the end of class

1. Dictionaries
• Create a dictionary called geology with the keys “Igneous” and “Metamorphic”. The values of these keys should be the definition of these words.
• Print the value for the key "Igneous"
• Add a new key-value pair “Sedimentary” with its definition.
• Print all of the values using the method values( )
2. Conditional statements
• Set $x$ to 5 and $y$ to 6. Test if they are equal using relational operators. Test if they are not equal using the relational operators.
• $x$ and $y$ are not equal. Test which one is larger by using the less than and greater than relational operators.
• Create new variables and apply the less than or equal to and greater than or equal to relational operators to these variables.
3. While loops
• Set $day$ to 1 and $fullMoon$ to 29
• Create a while loop that checks if $day$ is less than $fullMoon$. If it is, print $day$ and increment $day$ by 1
• If $day$ is greater than or equal to $fullMoon$, print "Today is a full moon."
4. If statements
• Set a variable $oldestCrust$ to 3.5e9, $oldestSeafloor$ to 180e6, $ageEarth$ to 4.5e9, and $ageSolarSystem$ to 4.5e9
• Create an if-else statement that compares the age of the crust with the age of the seafloor and prints out which is older
• Create an if-else statement that compares the age of the Earth and the age of the solar system and prints out whether or not they formed at the same time
5. For loops
• create a list of mountain ranges (Himalayas, Rocky, Trans-Antarctic, Andes, Alps, Appalachians, etc.)
• write a for loop that prints out all of the elements in your list
6. Nested loops
• Make a dictionary of volcanoes with the volcano names as keys and the values as the most recent eruption: "Mt St Helen's":1981, 'Pinatubo':1992, 'Krakatoa':2014, 'Anak Krakatoa': 2018, 'Yellowstone':-68000, 'Kilauea':2018"
• Make a nested loop: step through the dictionary of volcanoes. If the last eruption was within the last five years, then print 'Recent activity at ' along with the name of the volcano, otherwise print 'No recent activity at ' and the name of the volcano.
In [ ]: