Kodewick
Start learning →
Basic←→0 / 80

Over the bag limit?

#008BasicFunctions5 min

At check-in you say the weight limit, then put the bags on the scale one by one: over_limit(20, 8, 9, 5). Write over_limit(limit, *bags) to return how many kilos over you are; if you're not over, or there are no bags at all, return 0.

Examples
over_limit(20, 8, 9, 5)→2
over_limit(20)→0
main.py
def over_limit(limit, *bags):
    total = 0
    # your code here: add up all the bag weights into total
    if total > limit:
        # your code here: return how many kilos over
        pass
    return 0
Ctrl + Enter runs too
Result

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