मराठी

Write a program to search input any customer name and display customer phone number if the customer name is exist in the list.

Advertisements
Advertisements

प्रश्न

Write a program to search input any customer name and display customer phone number if the customer name is exist in the list.

कोड लेखन
Advertisements

उत्तर

Store customer name and phone number as key-value pairs in a dictionary, then search the customer name.

n = int(input("Enter number of customers: "))
customers = {}

for i in range(n):
    name = input("Enter customer name: ")
    phone_number = input("Enter phone number: ")
    customers[name] = phone_number

search_name = input("Enter customer name to search: ")

if search_name in customers:
    print("Customer phone number:", customers[search_name])
else:
    print("Customer name does not exist")
 
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1: Review of Phython - EXERCISE [पृष्ठ २७]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 1 Review of Phython
EXERCISE | Q 30. | पृष्ठ २७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×