Skip to main content
code•debug it•python
0s
+15 XP

Off-By-One Sum Loop Boundary

The function sum_to_n(5) should return 15 (1+2+3+4+5), but it currently returns 10. Find the bug in the range boundary.

python
def sum_to_n(n):
    total = 0
    for i in range(1, n): # Bug is here!
        total += i
    return total
Exit to Challenges