Advertisements
Advertisements
Question
Write a Python function add_contact() that accepts a dictionary phone_book, a name, and a phone number. The function should add the name and phone number to the dictionary. If the name already exists, print “Contact already exists” instead of updating it.
Code Writing
Advertisements
Solution
def add_contact(phone_book, name, number):
if name in phone_book:
print("Contact already exists")
else:
phone_book[name] = number
print("Contact added successfully")shaalaa.com
Is there an error in this question or solution?
