CS 140
Practice problems on Dictionaries

Here are some practice programming problems using dictionaries

These are not to be handed in, though you should feel free to ask questions about any of them outside of class. Remember that programming is an activity that you learn by doing.

  1. Write a program that stores in a dictionary a list of people's birthdays. To make the input simple, read in the three fields of the birthday (month, day, year) on separate lines. Your input might look like this:

    Enter name:bob
    Enter month: 2
    Enter day: 16
    Enter year: 1952

    Enter name:

    It this could keep up until you get a blank name.With each name you should enter the name and date in a dictionary, with key = name, value = date.
    After all of the input, have your program print all of the birthdays in the dictionary.

  2. Add a LookupName feature to the program from (1). This should ask the user for a name, and then print the birthday for that person. Make sure your program doesn't crash if you give it the name of someone who isn't in the dictionary.
  3. Add a LookupBirthday feature to the program from (1). This should ask for a birthday, and then print all of the people who had that birthday.
  4. Try rewriting this program so that the keys of the dictionary are the dates (use a tuple (m, d, y) for this) and the values are lists of all people with that date as their birthday.