English

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

Question

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

Code Writing
Advertisements

Solution

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
  Is there an error in this question or solution?
Chapter 1: Review of Phython - EXERCISE [Page 27]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 1 Review of Phython
EXERCISE | Q 30. | Page 27
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×