Command line contact management application in Python

Some of you were looking slightly fazed by my explanations in class today, so here is the code for the simplest contact manager application you could imagine. This one has no disk storage, but it should give you a reasonable idea of how to:

  • use a simple class
  • create and call basic functions
  • iterate over a list
class Contact:
    name = ""
    number = ""

def addContact():
    contact = Contact() = input("Enter contact name: ")
    contact.number = input("Enter contact number: ")
    print("Contact added.")
def getMenuChoice():
    print("1. Add new contact")
    print("2. Print all contacts")
    print("3. Quit")
    return input("Please enter your choice (1-3): ")

def printContacts():
    print("Printing contacts...")
    for itm in contactList:
        print ( + ", " + itm.number),

contactList = []
choice = getMenuChoice()
while choice != "3":
    if choice == "1":
    elif choice == "2":
    choice = getMenuChoice()

Here is what the program looks like when it runs:

python contact output

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s