Answer:
Check the output
Explanation:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 12 00:39:11 2018
author:
"""
stocks ={
"tomato soup": 20,
"cheese": 8,
"bread": 6,
"milk": 8,
"butter": 7,
"coffee": 8,
"ice cream": 5,
"orange juice": 12,
"bacon": 6,
"tortilla chips": 14,
"ramen": 24 }
prices ={
"tomato soup": 1.85,
"cheese": 3.99,
"bread": 2.50,
"milk": 3.59,
"butter": 1.99,
"coffee": 5.99,
"ice cream": 2.99,
"orange juice": 2.50,
"bacon": 5.49,
"tortilla chips": 3.00,
"ramen": 0.99 }
def grocery_cost(item_list,quantity_list):
totalcost = 0
for i in range(len(item_list)):
totalcost=totalcost+(quantity_list[i]*prices[item_list[i]])
return totalcost
def stock(item):
print("Number of itmes present in the stock:",stocks[item])
print("Welcome to the on-line grocery store!!")
print("Items that are available for purchase:")
for key in stocks.keys():
print(key)
#chosen foods
print("Enter the item with quantity or Enter 'Q' when you are done")
item_list=[]
quantity_list=[]
while True:
item=input('Enter the item name: ')
if item=='Q' or item=='q':
break
item_list.append(item)
while True:
quan=int(input('Enter the number of item: '))
if stocks[item] >=quan:
quantity_list.append(quan)
break
else:
stock(item)
print('Your requirement is higher than stock available. Please enter again!!')
print("\nTotal cost:", "$",grocery_cost(item_list,quantity_list))
Kindly check the output in the attached image below.