Programming Examples

Python program that repeatedly asks the user to enter product names and prices


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.

Solution

dic = { }
while True :
    product = input("enter the name of product (enter q for quit )= ")
    if product == "q" or product == "Q" :
        break
    else :
        price = int(input("enter the price of product = "))
        dic [ product ] = price
while True :
    name = input("enter the name of product those you are entered (enter q for quit )= ")
    if name == "q" or name == "Q" :
        break
    else :
        if name not in dic :
            print("name of product is invaild")
        else :
            print("price of product = ",dic[name])
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad