EX08 - dicts


Exercise 00 – Only Real 90s kids make the cut!

  1. In the comp110/exercises directory create a new folder named ex08_dicts
  2. Create a file named students_over_21.py in your comp110/exercises/ex08_dicts folder.
  3. Write a function with the following signature:
    1. Name: students_over_21
    2. Argument(s): A Dict[str, int] containing students’ names and their corresponding birth year
    3. Returns: A List[str] of student’s names.
  4. The function should return a list of student’s names that were born in or before 1999.

Example program run:

students_over_21({"Kris": 2000, "Kaki": 1998, "Marlee": 1994}) -> ["Kaki", "Marlee"]

Exercise 01 – Test Average!

  1. Create a file named average_score.py in your comp110/exercises/ex08_dicts folder.
  2. Write a function with the following signature:
    1. Name: average_score
    2. Argument(s): A Dict[str, float] containing students’ names and their test score.
    3. Returns: A float.
  3. The function should return the average test score amongst all students.

Example program run:

average_score({"Marc": 100.0, "Ezri": 100.0, "Kris": 23.7}) -> 74.56666666666666

Exercise 02 – Colors!

  1. Create a file named favorite_color.py in your comp110/exercises/ex08_dicts folder.
  2. Write a function with the following signature:
    1. Name: favorite_color
    2. Argument(s): A Dict[str, str] containing students’ names and their favorite color.
    3. Returns: A str.
  3. The function should return the color that appears most frequently.
    1. If there is a tie for most popular color, return the color that appeared in the dictionary first.

Example program run:

favorite_color({"Marc": "yellow", "Ezri": "blue", "Kris": "blue"}) -> "blue"

Testing

In your ex08_dicts directory, set up a file ex08_test.py where you should add tests to assert the correctness of your implementation. Before coming to office hours, you must have some failing test cases here.

Formatting and Documentation

  1. You should have a module docstring with a complete first sentence describing your progam at the start of each exercise.
  2. In each of your files, initialize a global variable named author set equal to your PID as a string

Submission

Go ahead and delete any submission zips lingering around in your workspace from the previous exercise.

When you are ready to submit for grading, close out any open Python Debug Console terminals using the Trash Can and then open up a clean, new terminal.

python -m tools.submission comp110/exercises/ex08_dicts

This should produce a submission timestamped with the current date/time for uploading on Gradescope.

Make a Backup Commit

  1. Open the Source Control panel (Command Palette: “Show SCM” or click the icon with three circles and lines on the activity panel).
  2. Notice the files listed under Changes. These are files you’ve made modifications to since your last backup.
  3. Move your mouse’s cursor over the word Changes and notice the + symbol that appears. Click that plus symbol to add all changes to the next backup. You will now see the files listed under “Staged Changes”.
    • If you do not want to backup all changed files, you can select them individually. For this course you’re encouraged to back everything up.
  4. In the Message box, give a brief description of what you’ve changed and are backing up. This will help you find a specific backup (called a “commit”) if needed. In this case a message such as, “Finished Exercise 0!!” will suffice.
  5. Press the Check icon to make a Commit (a version) of your work.
  6. Finally, press the Ellipses icon (…) and select “Push” to send this backed up version to your workspace repository space on GitHub.