In: Computer Science
Use Python program.
stock = {
"pineapple": 6,
"peach": 0,
"tangerine": 32,
"pear": 15
}
prices = {
"pineapple": 4,
"peach": 2,
"tangerine": 1.5,
"pear": 3
}
CODE:
#instructions
groceries = ['pineapple','tangerie','peach']
stock = {"pineapple": 6,"peach": 0,"tangerine": 32,"pear":
15}
prices = {"pineapple": 4,"peach": 2,"tangerine": 1.5,"pear":
3}
#inifinte loop
while(True):
#printing the menu
print('Enter 1 to enter item and quantity')
print('Enter 2 to quit')
#user entering the choice
choice = int(input())
#if choice == 1
if(choice == 1):
#user enters the item and quantity
item = input('Enter the item: ')
quantity = int(input('Enter the quantity: '))
#if the item is not in the list
if(item not in stock.keys()):
#prints the message
print('Item not in stock!')
else:
#if it is available in the list
#but the quantity entered is greater than
#the quantity available
if(quantity > stock[item]):
#prints the quantity available and price of that qty
print('Quantity entered is greater than available')
print('Quantity available is '+str(stock[item]))
print('Price for that quantity is: $'
+str(stock[item]*prices[item]))
else:
#if user entered a valid quantity
#printing the cost of that quantity
print('Cost of {} {} is: ${}'
.format(str(quantity),item,str(prices[item]*quantity)))
#reducing the amount from the stock
stock[item] -= quantity
elif(choice == 2):
break
else:
print('Invalid Choice!')
_______________________________________________
CODE IMAGES:
_____________________________________________
OUTPUT:
_______________________________________________
Feel free to ask any questions in the comments section
Thank You!