130k views
4 votes
Create a new file that builds a shopping list from a user. There should be a input query that asks the user to list an item and the number of those items. Two lists should be built that reflects the items on the list and the number of each items that are to be purchased. The list should build until the user is done. b. Call up your function grocery_cost to check the stock and build your total cost. Your program should let the user know if the items they want are in stock. If there is not enough stock, your program should let the user know that and offer them the number that are in stock. You will need to edit your grocery_cost function to reflect that a number of items will be selected instead of just one. c. Call up your stock_check function and print items that need restocking

1 Answer

7 votes

Answer:

Check the output

Step-by-step 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("\\Total cost:", "$",grocery_cost(item_list,quantity_list))

Kindly check the output in the attached image below.

Create a new file that builds a shopping list from a user. There should be a input-example-1
User Thunderbeef
by
5.4k points