Adding Values with a For Loop

Write a program that gets an integer from the user. Add up all the numbers from 1 to that number, and display the total. Use a for loop to do it.

You have done something like this before.

Name the file sum_for_loop.py

Number: 5

1 2 3 4 5
The sum is 15.
Number: 8

1 2 3 4 5 6 7 8
The sum is 36.

©2021 Daniel Gallo

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

Creative Commons License

Adapted for Python from Graham Mitchell’s Programming By Doing