17.8 Exercises
From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython1 class period4 exercises6 graded tests
17.8 Exercises
Read first in the book: 17.5 Structuring Nested Data, 17.6 Deep and Shallow Copies, 17.7 Extracting from Nested Data.
Exercise 1
Iterate through the list so that if the character 'm' is in the string, then it should be added to a new list called m_list. Hint: Because this isn't just a list of lists, think about what type of object you want your data to be stored in. Conditionals may help you.
Open the
01folder and editmain.py. Run Tests checks it.
Exercise 2
The nested dictionary, pokemon, shows the number of various Pokemon that each person has caught while playing Pokemon Go. Find the total number of rattatas, dittos, and pidgeys caught and assign to the variables r, d, and p respectively. Do not hardcode. Note: Be aware that not every trainer has caught a ditto.
Open the
02folder and editmain.py. Run Tests checks it.
Exercise 3
Below, we have provided a nested list called big_list. Use nested iteration to create a dictionary, word_counts, that contains all the words in big_list as keys, and the number of times they occur as values.
Open the
03folder and editmain.py. Run Tests checks it.
Exercise 4
Provided is a dictionary that contains pokemon go player data, where each player reveals the amount of candy each of their pokemon have. If you pooled all the data together, which pokemon has the highest number of candy? Assign that pokemon to the variable most_common_pokemon.
Open the
04folder and editmain.py. Run Tests checks it.
For teachers
17.8 Exercises
Students read Foundations of Python Programming's “Exercises” in CS Room and work through its 4 Python coding exercises (4 graded).
- Time: 1 class period
- Tests: 6 in 4 graded exercises, set up for you when you import the lesson
Reading first
Exercises
| Folder | Grading | Tests |
|---|---|---|
01 | Autograded | 1 |
02 | Autograded | 3 |
03 | Autograded | 1 |
04 | Autograded | 1 |