Home > Computer Programming > Command line contact management application in Python

Command line contact management application in Python

October 14, 2014 Leave a comment Go to comments

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()
    contact.name = 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.name + ", " + 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

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s