菜谱上的用量(克)是 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
写好了先点「运行」试试示例,没问题再点「提交」。