#首先我們給個list
shopping_list = ["banana", "orange", "apple"]
#定義Dictionary
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
# 定義函數,裡面有個變數food,然後利用條件式,如果有庫存就加進總計,庫存減一
def compute_bill(food):
total= 0
for number in food:
if stock[number] > 0:
total += prices[number]
stock[number] -= 1
return total
沒有留言:
張貼留言