19.5 Chapter Assessment

From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython2 class periods8 exercises8 graded tests

README.md

19.5 Chapter Assessment

Exercise 1

The code below takes the list of country, country, and searches to see if it is in the dictionary gold which shows some countries who won gold during the Olympics. However, this code currently does not work. Correctly add try/except clause in the code so that it will correctly populate the list, country_gold, with either the number of golds won or the string "Did not get gold".

Open the 01 folder and edit main.py. Run Tests checks it.

Exercise 2

Provided is a buggy for loop that tries to accumulate some values out of some dictionaries. Insert a try/except so that the code passes.

Open the 02 folder and edit main.py. Run Tests checks it.

Exercise 3

The list, numb, contains integers. Write code that populates the list remainder with the remainder of 36 divided by each number in numb. For example, the first element should be 0, because 36/6 has no remainder. If there is an error, have the string "Error" appear in the remainder.

Open the 03 folder and edit main.py. Run Tests checks it.

Exercise 4

Provided is buggy code, insert a try/except so that the code passes.

Open the 04 folder and edit main.py. Run Tests checks it.

Exercise 5

Write code so that the buggy code provided works using a try/except. When the codes does not work in the try, have it append to the list attempt the string "Error".

Open the 05 folder and edit main.py. Run Tests checks it.

Exercise 6

The following code tries to append the third element of each list in conts to the new list third_countries. Currently, the code does not work. Add a try/except clause so the code runs without errors, and the string 'Continent does not have 3 countries' is appended to third_countries instead of producing an error.

Open the 06 folder and edit main.py. Run Tests checks it.

Exercise 7

The buggy code below prints out the value of the sport in the list sport. Use try/except so that the code will run properly. If the sport is not in the dictionary, ppl_play, add it in with the value of 1.

Open the 07 folder and edit main.py. Run Tests checks it.

Exercise 8

Provided is a buggy for loop that tries to accumulate some values out of some dictionaries. Insert a try/except so that the code passes. If the key is not there, initialize it in the dictionary and set the value to zero.

Open the 08 folder and edit main.py. Run Tests checks it.

For teachers

19.5 Chapter Assessment

Students read Foundations of Python Programming's “Chapter Assessment” in CS Room and work through its 8 Python coding exercises (8 graded).

  • Time: 2 class periods
  • Tests: 8 in 8 graded exercises, set up for you when you import the lesson

Exercises

FolderGradingTests
01Autograded1
02Autograded1
03Autograded1
04Autograded1
05Autograded1
06Autograded1
07Autograded1
08Autograded1