Predict for Loop Sum
Predict Output Easy
Question
What does this code print?
Code
total = 0
for i in range(1, 5):
total += i
print(total)
Hint
Sum the values 1 + 2 + 3 + 4.
Explanation
range(1, 5) produces 1, 2, 3, 4. The loop adds each to total: 0+1=1, 1+2=3, 3+3=6, 6+4=10. print outputs: 10
Related Resources
Related Lessons
- Conditions and Loops
for 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.