Kodewick
开始学 →
小挑战←→0 / 100

零食小票

#076小挑战函数综合约 6 分钟

零食店的小票:每一行是 [单价, 数量]。先写 line_total(price, qty) 算一行;再写 receipt_total(lines),用它把每行加起来。满 100 减 10。没有东西就是 0。

示例
receipt_total([[5, 2], [3, 4]])→22
receipt_total([[30, 2], [20, 2]])→90
main.py
def line_total(price, qty):
    # 在这里写:一行的钱
    return 0

def receipt_total(lines):
    total = 0
    for price, qty in lines:
        total += line_total(price, qty)
    # 在这里写:满 100 减 10

    return total
Ctrl + Enter 也能运行
结果

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