Advertisements
Advertisements
प्रश्न
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.
कोड लेखन
Advertisements
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
