Kodewick
開始學 →
基礎←→0 / 112

菜譜換人數

#051基礎round(grams * people / 2, 1)約 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 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。