Kodewick
Start learning →
Starter←→0 / 100

Add up to n

#015StarterLoopsNumbers3 min

Sam wants to know what 1 + 2 + 3 + … + n comes to. Write sum_to(n) to add up 1 to n with a loop. For n of 0, return 0.

Examples
sum_to(4)→10
sum_to(10)→55
main.py
def sum_to(n):
    total = 0
    for i in range(1, n + 1):
        # your code here: add i to total
        pass
    return total
Ctrl + Enter runs too
Result

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