223k views
0 votes
Write a program that will add up the series of numbers: 105, 104, 103... 321. The program should print the running total as well as the total at the end. The program should use one for loop, the range() function, and one print() command.

1 Answer

0 votes

Final answer:

To add up the series of numbers from 105 to 321 using Python, you can use a for loop and the range() function to iterate through the numbers and keep track of the running total. Here is a step-by-step solution with code example.

Step-by-step explanation:

To add up the series of numbers from 105 to 321, we can use a for loop and the range() function in Python. Here is the step-by-step solution:

  1. Initialize a variable 'total' as 0 to keep track of the running total.
  2. Use a for loop with the range() function to iterate through the numbers from 105 to 321.
  3. Inside the loop, add each number to the 'total' variable.
  4. Print the 'total' variable inside the loop to see the running total.
  5. Finally, after the loop ends, print the 'total' variable to get the total sum.

Here is the code:

total = 0
for num in range(105, 322):
total += num
print('Running Total:', total)

print('Total:', total)

This program will print the running total at each step and the final sum at the end.

User Birdsarah
by
8.2k points