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

平均分

#044基礎sum() / len()約 4 分鐘

老師把全班的分數放在一個列表裡。寫 average(scores),返回平均分,用 round 保留 1 位小數。如果列表是空的(還沒人交卷),返回 0。

示例
average([90, 80, 70])→80.0
average([88, 92])→90.0
average([])→0
main.py
def average(scores):
    if len(scores) == 0:
        return 0
    # 在這裡寫:總分除以人數,保留 1 位小數

Ctrl + Enter 也能執行
結果

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