菜譜上的用量(克)是 2 個人吃的。寫 scale_recipe(amounts, people),返回 people 個人要用的量:每樣乘 people 再除以 2,用 round 保留 1 位小數。
scale_recipe([200, 50, 3], 4)→[400.0, 100.0, 6.0]scale_recipe([100, 15], 3)→[150.0, 22.5]def scale_recipe(amounts, people):
new_amounts = []
for grams in amounts:
# 在這裡寫:算出新的量,放進 new_amounts
pass
return new_amounts
寫好了先點「執行」試試示例,沒問題再點「提交」。