Q. Write a program that repeatedly asks the user to enter product names and prices. Store all of these in a dictionary whose keys are the product names and whose values are the price.
When the user is done entering products and price, allow them to repeatedly enter a product name and print the corresponding price or a message if the product is not in dictionary.
You can understand by Watching video :-
Answer :-
dic = { } while True : product = input("Enter the name of product (enter q for quit )= ") if product == "q" or product == "Q" : print() break else : price = int(input("Enter the price of product = ")) dic [ product ] = price while True : name = input("Enter the name of product those you have entered (enter q for quit )= ") if name == "q" or name == "Q" : break else : if name not in dic : print("Name of product is invalid") print() else : print("Price of product = ",dic[name]) print()
Output :-
Enter the name of product (enter q for quit )= Path
Enter the price of product = 100
Enter the name of product (enter q for quit )= Walla
Enter the price of product = 85
Enter the name of product (enter q for quit )= Portal
Enter the price of product = 80
Enter the name of product (enter q for quit )= Express
Enter the price of product = 70
Enter the name of product (enter q for quit )= q
Enter the name of product those you have entered (enter q for quit )= Walla
Price of product = 85
Enter the name of product those you have entered (enter q for quit )= Python
Name of product is invalid
Enter the name of product those you have entered (enter q for quit )= Portal
Price of product = 80
Enter the name of product those you have entered (enter q for quit )= q
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )