Embed presentation
Downloaded 12 times




































![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 price in food:
if stock[price] > 0:
total += prices[price]
stock[price] -= 1
return total](https://image.slidesharecdn.com/pythonprogramminglab11-150304091424-conversion-gate01/75/Python-programming-lab-11-37-2048.jpg)




This Python code defines a shopping list, stock inventory, and prices dictionaries. It then defines a compute_bill function that takes a food list as a parameter, calculates the total cost by looking up the price of each food in the prices dictionary if it is available in stock, subtracts 1 from the stock amount, and returns the total.




































![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 price in food:
if stock[price] > 0:
total += prices[price]
stock[price] -= 1
return total](https://image.slidesharecdn.com/pythonprogramminglab11-150304091424-conversion-gate01/75/Python-programming-lab-11-37-2048.jpg)



