# A program that implements a rudimentary phone catalog: # - First asks the user to specify the number of entries in the catalog. # - Second asks the user to enter enter names and phone numbers. # - Third, enters in a loop where the user enters a name and the # program looks up and prints out the corresponding phone number. # This is an improved version of phone_numbers_1.py. The improvements are: # - the program allows the user to enter "q" to exit the program. # - if the name is not found, the program prints out a message stating that # the name was not found. # get number of entries N = input("enter number of entries: ") # initialize lists that will store names and phone numbers # convention: the programmer will make sure that numbers[i] stores # the phone number for names[i]. names = [] numbers = [] # get from the user the names and phone numbers. for i in range(0, N): name = raw_input("enter a name: ") number = raw_input("enter a phone number for " + name + ": ") names.append(name) numbers.append(number) # now, get in a loop where the user enters a name, and the computer # looks up and prints out the corresponding phone number. while True: name = raw_input("enter a name to look up: ") if name == "q": break name_found = False for i in range(0, N): if name == names[i]: print "the phone number of", name, "is", numbers[i] name_found = True if (name_found == False): print "Name ", name, "is not in this catalog"