In Exercise 08, we’ll be constructing 2 functions in 2 python files.
0. Pull the skeleton code
You will find the starter files needed by “pulling” from the course workspace repository. Before beginning, be sure to:
- Be sure you are in your course workspace. Open the file explorer and you should see your work for the course. If you do not, open your course workspace through File > Open Recent.
- Open the Source Control View by clicking the 3-node (circles) graph (connected by lines) icon in your sidebar or opening the command palatte and searching for Source Control.
- Click the Ellipses in the Source Control pane and select “Pull” from the drop-down menu. This will begin the pulling process from the course repository. It should silently succeed.
- Return to the File Explorer pane and open the
exercises
directory. You should see it now contains the directory namedex08
. If you expand those directories, you will see the starter files for the two Python programs in this exercise.
If the above did not work, try the following:
- Click the Ellipses in the Source Control pane and select “Pull, Push” from the drop-down menu. Then select “Pull from”. Then select “upstream” and the
main
option. This will begin the pulling process from the course repository. It should silently succeed. - Return to the File Explorer pane and open the
exercises
directory. You should see it now contains another directory namedex08
. If you expand that directory, you should see the starter files
Part 1. Only (Almost) Real 90s kids make the cut!
Inside your ex08
folder, you should see a file named over_21.py
. Inside you’ll see the skeleton of a main function and a call at the bottom following the if __name__ == "__main__"
idiom.
over_21
Create a function in your over_21.py
file called over_21
. It has the following specifications:
- It has one parameter, of type
dict[str, int]
of names and corresponding birth years. - It returns a
list[str]
of student’s names.
The function should return a list of student’s names that were born in or before 2000.
You can check the correctness of your over_21
function by calling it in main
, printing the result, then running the program with the same command from above.
An example:
The results of which would look like:
$ python -m exercises.ex08.over_21
["Kaki", "Marlee"]
Part 2: Colors
Create a function in your favorite_color.py
file called favorite_color
. It has the following specifications:
- It has one parameter, of type
dict[str, str]
of names and favorite colors. - It returns a
str
which is the color that appears most frequently.- If there is a tie for most popular color, return the color that appeared in the dictionary first.
You can also check the correctness of your favorite_color
function by calling it in main
, printing the result, then running the program with the same command from above.
An example:
The results of which would look like:
$ python -m exercises.ex08.favorite_color
blue
3. Make a Backup Checkpoint “Commit”
As you make progress on this exercise, making backups is encouraged. Note that you do not have to make a backup in order to submit your work, though you are encouraged to before each submission so that you can revert back to a previous point in your project if you accidentally change something you did not intend to.
- Open the Source Control panel (Command Palette: “Show SCM” or click the icon with three circles and lines on the activity panel).
- Notice the files listed under Changes. These are files you’ve made modifications to since your last backup.
- 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.
- 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, “Progress on Exercise 3” will suffice.
- Press the Check icon to make a Commit (a version) of your work.
- Finally, press the Ellipses icon (…), look for “Pull/Push” submenu, and select “Push to…”, and in the dropdown select your backup repository.
4. Submit to Gradescope for Grading
Login to Gradescope and select the assignment named “EX08 - Dictionaries”. You’ll see an area to upload a zip file. To produce a zip file for autograding, return back to Visual Studio Code.
If you do not see a Terminal at the bottom of your screen, open the Command Palette and search for “View: Toggle Integrated Terminal”.
To produce a zip file for ex08
, type the following command (all on a single line):
python -m tools.submission exercises/ex08
In the file explorer pane, look to find the zip file named “21.mm.dd-hh.mm-exercises-ex08.zip”. The “mm”, “dd”, and so on, are timestamps with the current month, day, hour, minute. If you right click on this file and select “Reveal in File Explorer” on Windows or “Reveal in Finder” on Mac, the zip file’s location on your computer will open. Upload this file to Gradescope to submit your work for this exercise.