16.9 Chapter Assessment

From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython2 class periods11 exercises11 graded tests

README.md

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 01 folder and edit main.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 02 folder and edit main.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 03 folder and edit main.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 04 folder and edit main.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 05 folder and edit main.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 06 folder and edit main.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 07 folder and edit main.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 08 folder and edit main.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 09 folder and edit main.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 10 folder and edit main.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 11 folder and edit main.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

FolderGradingTests
01Autograded1
02Autograded1
03Autograded1
04Autograded1
05Autograded1
06Autograded1
07Autograded1
08Autograded1
09Autograded1
10Autograded1
11Autograded1