Sum Numbers 1 to 10
Beginner · Write the code · from Python For Loops: Iterate Over Anything with Examples
From the lesson: Python For Loops: Iterate Over Anything with Examples
Imagine you're a teacher with 30 students. You need to print a report card for each one. Would you write 30 separate print statements? Of course not. You'd tell the computer: "for each student, print their report card." That's exactly what a for loop does.
Read the lessonUse range() and a for loop to calculate the sum of all numbers from 1 to 10 (inclusive). Print the result.
Expected output:
Sum: 55# Calculate the sum of numbers 1 through 10 using range()
total = 0
# Write your for loop here
print(f"Sum: {total}")
More For Loops exercises
- Print the Shopping ListBeginner
- Predict the OutputBeginner
- Fix the Bug: Letter CounterBeginner
- Numbered MenuBeginner
- Reverse a StringBeginner
- Student Grade ReportBeginner
All Python exercises · 50 practice problems · Control Flow quiz