[英]Why does the for loop return None?
我正在Code Academy進行練習,以遍歷shopping_list
。 為什么以下代碼結果在結果中返回額外的None
?
shopping_list = ["banana","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 x in food:
print x
total += prices[x]
compute_bill(shopping_list)
shopping_list = ["banana","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 x in food:
print x
total += prices[x]
return total
print(compute_bill(shopping_list))
您需要使用return
語句來獲取函數compute_bill
的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.