Kodewick
开始学 →
基础←→0 / 100

菜谱换人数

#051基础列表数字约 4 分钟

菜谱上的用量(克)是 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]
main.py
def scale_recipe(amounts, people):
    new_amounts = []
    for grams in amounts:
        # 在这里写:算出新的量,放进 new_amounts
        pass
    return new_amounts
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。