A Day at the Supermarket

super12 super1 super2 super3 super4 super5 super6 super7 super8 super9 super10 super11 super12 super13

This lab is about using lists and functions to create a program that can give the total price of groceries and update the stock when needed. The first part is used to remind the student about the usage of the for loop and how it can work with the list functions. After that, it’s time to start building what would seem like a list of grocery goods. ┬áPrices and stocks are set, now ┬áthe total function must be made to calculate how much money would be gained if all the goods were sold.

shopping_list = [“banana”, “orange”, “apple”]

stock = {
“banana”: 6,
“apple”: 0,
“orange”: 32,
“pear”: 15

prices = {
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3

# Write your code below!
def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total = total + prices[item]
stock[item] = stock[item] – 1
return total

Code used to make the program for Lab.