Unit A – Dictionaries


Create a Python script named contacts.py that fulfills the requirements below. Use Gist and the submission form to turn in this lab.


First, hand populate a contact list stored as a nested dictionary with the contact information for at least three different professors. You can see the contact information for the Analytics professors at http://analytics.usfca.edu/artsci/msan/faculty/ (you may have to click on the professor's name to see additional contact information). 

Use the professor's last name as the key for the outer dictionary, and make sure each inner dictionary has a "name" key with the professor's full name. Here is an example:

contact_dict = {}

contact_dict["Engle"] = {
    "name": "Sophie Engle",
    "email": "sjengle@cs.usfca.edu",
    "phone": "(415) 422-4174",
    "web": "http://sjengle.cs.usfca.edu",
    "twitter": "@sjengle"

Then, prompt the user for a last name. Check if that last name is a key in your dictionary. You may have to trim the string and change the case. If the name is not in the dictionary, output a warning message and exit. For example:

Please enter a last name: Smith
I'm sorry, I do not have a Professor Smith in my contact list.

If the name is in the dictionary, print out first the professor's full name and then the remainder of the contact information (one item per line) in sorted order. For example:

Please enter a last name: engle

Name: Sophie Engle
Email: sjengle@cs.usfca.edu
Phone: (415) 422-4174
Twitter: @sjengle
Web: http://sjengle.cs.usfca.edu

Try to include as much information as you can with each professor!

SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser

Template file.  1k v. 2 Aug 2, 2012, 9:06 PM Sophie Engle