Introduction to Computer Programming: Lab 7

Phone book

A simple introduction to dictionaries


Instructions


Exercises

  1. Warmup. Experiment with sets and dictionaries by typing these examples and other examples like them into IDLE's shell.


  2. Out of the box, the "phone REPL" should run, though most options are not yet implemented or are only partially implemented. Your first real task is to complete the option for adding a new entry to the phone book. Most of the code has been added for you.

  3. Complete the REPL option for finding the number associated with a name. Your code should produce output to match this dialogue:

    Select menu option: a
    Enter new user name: Minerva
    Enter phone#: 4444
    Ok.
    
    Select menu option: f
    Enter name to lookup: Minerva
    Minerva's phone number is 4444.
  4. Add the REPL option for editing an entry. Follow this model:

    Select menu option: e
    Enter name to change number for: Hermione
    Hermione is not in your phone book!
    
    Select menu option: f
    Enter name to lookup: Minerva
    Minerva's phone number is 4444.
    
    Select menu option: e
    Enter name to change number for: Minerva
    Enter new phone#: 2222
    Ok.
    
    Select menu option: f
    Enter name to lookup: Minerva
    Minerva's phone number is 2222.
  5. Add the REPL option for deleting an entry. Follow this model:

    Select menu option: f
    Enter name to lookup: Minerva
    Minerva's phone number is 4444.
    
    Select menu option: d
    Enter name to remove from phone book: Minerva
    Ok.
    
    Select menu option: f
    Enter name to lookup: Minerva
    Minerva is not in your phone book!
  6. Add the REPL option for viewing the number of entries in the book. Write your code to follow these examples:

    Select menu option: n
    Your phone book is empty!
    
    Select menu option: a
    Enter new user name: Mike
    Enter phone#: 2490
    Ok.
    
    Select menu option: n
    There is only one entry in your phone book.
    
    Select menu option: a
    Enter new user name: Jim
    Enter phone#: 2673
    Ok.
    
    Select menu option: n
    There are 2 entries in your phone book.
  7. Add the REPL option for listing all the entries in the book. For example:

    Select menu option: l
    
    Mike: 2490
    Jim: 2673

    If the book is empty, indicate that fact.


Time permitting