Python

Names and Phone Numbers

[using a Python dictionary]

14 points 

Introduction

This project stores the names and phone numbers of every family in a town. It then provides various methods that allow the user to access this information. (A webpage said that there are 5203 households in Metuchen, so there are 5203 name - phone number pairs in this project.) The 2010 census data includes a spreadsheet that lists the most common last names in the U.S. I used the 5203 most common last names in the U.S. for this project. The phone numbers are fake; I made them up.

Here is a summary of the methods in the project:

Some info on a Python dictionary:

A dictionary links or maps a 'key' to a 'value'. For example, if the dictionary records a person's favorite color, you could have:

colors = {} #declares a dictionary
colors['Bill'] = 'blue' #Here, 'Bill' is the key and 'blue' is the value.
colors['Jean'] = 'purple'
colors['Carlos'] = 'red'

# Run the following code to see what prints, and what that tells you about how dictionaries work:
print(colors)

print('Jean in the dictionary:','Jean' in colors)

keys = colors.keys()
print('keys',keys)

values = colors.values()
print('values',values)

items = colors.items()
print('items',items)

for color in colors:
   print('key:',color)

 

Videos

The video below shows the method isSpamCall() being run. The video includes audio.

 

The video below shows the method isResident() being run. The video includes audio.

 

The video below shows the method lookUpName() being run. The video includes audio.

 

The video below shows the method lookUpNumber() being run. The video includes audio.

 

The video below shows the method addResident() being run. The video includes audio.

 

The video below shows the extra-credit version of the method lookUpName() being run. The video includes audio.

 

Starting Point

Download NamesAndNumbers.py as a starting point for the project. The file guides you towards completing the program. Also download lastNames.txt, which is the project's input file.

 

Extra Credit

3 points

As mentioned above, you can write an extra-credit version of lookUpName(). Some suggestions for writing the extra-credit version of lookUpName() are given in NamesAndNumbers.py.