11.12 Chapter Assessment

From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython3 class periods17 exercises23 graded tests

README.md

11.12 Chapter Assessment

Exercise 1

At the halfway point during the Rio Olympics, the United States had 70 medals, Great Britain had 38 medals, China had 45 medals, Russia had 30 medals, and Germany had 17 medals. Create a dictionary assigned to the variable medal_count with the country names as the keys and the number of medals the country had as each key's value.

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

Exercise 2

Given the dictionary swimmers, add an additional key-value pair to the dictionary with "Phelps" as the key and the integer 23 as the value. Do not rewrite the entire dictionary.

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

Exercise 3

Add the string "hockey" as a key to the dictionary sports_periods and assign it the value of 3. Do not rewrite the entire dictionary.

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

Exercise 4

The dictionary golds contains information about how many gold medals each country won in the 2016 Olympics. But today, Spain won 2 more gold medals. Update golds to reflect this information.

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

Exercise 5

Create a list of the countries that are in the dictionary golds, and assign that list to the variable name countries. Do not hard code this.

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

Exercise 6

Provided is the dictionary, medal_count, which lists countries and their respective medal count at the halfway point in the 2016 Rio Olympics. Using dictionary mechanics, assign the medal count value for "Belarus" to the variable belarus. Do not hardcode this.

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

Exercise 7

The dictionary total_golds contains the total number of gold medals that countries have won over the course of history. Use dictionary mechanics to find the number of golds Chile has won, and assign that number to the variable name chile_golds. Do not hard code this!

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

Exercise 8

Provided is a dictionary called US_medals which has the first 70 medals that the United States has won in 2016, and in which category they have won it in. Using dictionary mechanics, assign the value of the key "Fencing" to a variable fencing_value. Remember, do not hard code this.

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

Exercise 9

The dictionary Junior shows a schedule for a junior year semester. The key is the course name and the value is the number of credits. Find the total number of credits taken this semester and assign it to the variable credits. Do not hardcode this -- use dictionary accumulation!

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

Exercise 10

Create a dictionary, freq, that displays each character in string str1 as the key and its frequency as the value.

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

Exercise 11

Provided is a string saved to the variable name s1. Create a dictionary named counts that contains each letter in s1 and the number of times it occurs.

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

Exercise 12

Create a dictionary, freq_words, that contains each word in string str1 as the key and its frequency as the value.

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

Exercise 13

Create a dictionary called wrd_d from the string sent, so that the key is a word and the value is how many times you have seen that word.

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

Exercise 14

Create the dictionary characters that shows each character from the string sally and its frequency. Then, find the most frequent letter based on the dictionary. Assign this letter to the variable best_char.

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

Exercise 15

Find the least frequent letter. Create the dictionary characters that shows each character from string sally and its frequency. Then, find the least frequent letter in the string and assign the letter to the variable worst_char.

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

Exercise 16

Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Letters should not be counted separately as upper-case and lower-case. Intead, all of them should be counted as lower-case.

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

Exercise 17

Create a dictionary called low_d that keeps track of all the characters in the string p and notes how many times each character was seen. Make sure that there are no repeats of characters as keys, such that "T" and "t" are both seen as a "t" for example.

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

For teachers

11.12 Chapter Assessment

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

  • Time: 3 class periods
  • Tests: 23 in 17 graded exercises, set up for you when you import the lesson

Exercises

FolderGradingTests
01Autograded1
02Autograded1
03Autograded1
04Autograded1
05Autograded1
06Autograded1
07Autograded1
08Autograded1
09Autograded1
10Autograded1
11Autograded1
12Autograded1
13Autograded1
14Autograded2
15Autograded2
16Autograded4
17Autograded2