Menu
Coddy logo textTech

View Contact

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

challenge icon

Challenge

Medium

Create a function named view_contact that displays details of a specific contact.

Your function should:

  1. Take a contact book dictionary as a parameter
  2. Get a contact name from user input (using input())
  3. Display the contact's details if found
  4. Print "Contact not found!" if the contact doesn't exist

When displaying a contact, use this exact format:

Name: [name]
Phone: [phone]
Email: [email]
Address: [address]

Example:

If the contact book contains Alice's information and the user enters "Alice", output:

Name: Alice
Phone: 123-456-7890
Email: alice@example.com
Address: 123 Main St

If the user enters "Bob" (who doesn't exist), output:

Contact not found!

Note: Your function should only output the contact details or the error message - no additional prompting text.

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")


def add_contact(contact_book):
    name = input()
    if name in contact_book:
        print("Contact already exists!")
        return
    phone = input()
    email = input()
    address = input()
    contact_book[name] = {"phone": phone, "email": email, "address": address}
    print("Contact added successfully!")

All lessons in Logic & Flow