For Loop Sum
Predict Output Easy
Question
What does this code print?
Code
total = 0
for i in range(5):
total += i
print(total)
Hint
0+1+2+3+4=10.
Explanation
range(5) gives 0,1,2,3,4. total accumulates: 0+0=0, 0+1=1, 1+2=3, 3+3=6, 6+4=10. Output: 10.
Related Resources
Related Lessons
- Conditions & Loops
Learn conditions and loops.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.