Kodewick
Start learning →
Basic←→0 / 80

A crate of pencils

#067BasicRecursionNumbers4 min

A crate holds boxes, each box holds packs, each pack holds pencils. levels lists how many each layer holds, outside first, like [2, 3, 10]. Write pencils(levels) for the total: the first number times what the inner layers give. If levels is empty, that's just 1 pencil.

Examples
pencils([2, 3, 10])→60
pencils([])→1
main.py
def pencils(levels):
    if levels == []:
        return 1
    # your code here: the first layer's number times the result for the inner layers (instead of return 0)
    return 0
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.