16.9 Chapter Assessment
From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython2 class periods11 exercises11 graded tests
16.9 Chapter Assessment
Exercise 1
Sort the following string alphabetically, from z to a, and assign it to the variable sorted_letters.
Open the
01folder and editmain.py. Run Tests checks it.
Exercise 2
Sort the list below, animals, into alphabetical order, a-z. Save the new list as animals_sorted.
Open the
02folder and editmain.py. Run Tests checks it.
Exercise 3
Write code to rearrange the strings in the list winners so that they are in alphabetical order by first name from A to Z.
Open the
03folder and editmain.py. Run Tests checks it.
Exercise 4
Write code to switch the order of the winners list so that it is now Z to A, by first name. Assign this list to the variable z_winners.
Open the
04folder and editmain.py. Run Tests checks it.
Exercise 5
Write code to switch the order of the winners list so that it is now A to Z by last name. Assign this list to the variable z_winners.
Open the
05folder and editmain.py. Run Tests checks it.
Exercise 6
The dictionary, medals, shows the medal count for six countries during the Rio Olympics. Sort the country names so they appear alphabetically. Save this list to the variable alphabetical.
Open the
06folder and editmain.py. Run Tests checks it.
Exercise 7
Given the same dictionary, medals, now sort by the medal count. Save the three countries with the highest medal count to the list, top_three.
Open the
07folder and editmain.py. Run Tests checks it.
Exercise 8
We have provided the dictionary groceries. You should return a list of its keys, but they should be sorted by their values, from highest to lowest. Save the new list as most_needed.
Open the
08folder and editmain.py. Run Tests checks it.
Exercise 9
Create a function called last_four that takes in a single ID number and returns the last four digits. For example, the number 17573005 should return 3005. Then, use the resulting function to sort the list of ids stored in the variable, ids, from lowest to highest. Save this sorted list in the variable, sorted_ids. Hint: Remember that only strings can be indexed, so conversions may be needed.
Open the
09folder and editmain.py. Run Tests checks it.
Exercise 10
Sort the list ids by the last four digits of each id. Do this using lambda and not using a defined function. Save this sorted list in the variable sorted_id.
Open the
10folder and editmain.py. Run Tests checks it.
Exercise 11
Sort the following list by each element's second letter a to z. Do so by using lambda. Assign the resulting value to the variable lambda_sort.
Open the
11folder and editmain.py. Run Tests checks it.
For teachers
16.9 Chapter Assessment
Students read Foundations of Python Programming's “Chapter Assessment” in CS Room and work through its 11 Python coding exercises (11 graded).
- Time: 2 class periods
- Tests: 11 in 11 graded exercises, set up for you when you import the lesson
Exercises
| Folder | Grading | Tests |
|---|---|---|
01 | Autograded | 1 |
02 | Autograded | 1 |
03 | Autograded | 1 |
04 | Autograded | 1 |
05 | Autograded | 1 |
06 | Autograded | 1 |
07 | Autograded | 1 |
08 | Autograded | 1 |
09 | Autograded | 1 |
10 | Autograded | 1 |
11 | Autograded | 1 |