python
Write a program where you store product names and prices in a dictionary whose keys are the product names and whose values are the prices.
a) Check whether a certain item is part of the dictionary.
b) Remove a certain item from the dictionary.
c) Empty the dictionary
Answers
Answered by
3
Answer:
n = int(input(‘Enter number of products : ‘))
prod = {}
for i in range(n):
p = input(‘Enter product name : ‘)
prod[p] = int(input(‘Enter its price : ‘))
q = True
while q:
p = input(‘Enter product for price or q to exit : ‘)
if p == ‘q’:
break
if p in prod:
print(‘price of’, p, ‘is’, prod[p])
else:
print(p, ‘is not here’)
Similar questions