Menu
Coddy logo textTech

Add Contact

Part of the Logic & Flow section of Coddy's Python journey — lesson 18 of 78.

challenge icon

Challenge

Easy

Now, create the add_contact function that takes one argument: contact_book (a dictionary). The function should:

  1. Get input for the contact's name, phone, email, and address.
  2. Check if the name already exists in the dictionary. If it does, print: "Contact already exists!".
  3. If not, save the contact in the following format:

    contact_book[name] = {
    	"phone": phone,
    	"email": email,
    	"address": address
    }

    Then print: "Contact added successfully!".

Try it yourself

def display_menu():
    print("Contact Book Menu:")
    print("1. Add Contact")
    print("2. View Contact")
    print("3. Edit Contact")
    print("4. Delete Contact")
    print("5. List All Contacts")
    print("6. Exit")

All lessons in Logic & Flow