मराठी

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. - Computer Science (Python)

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×