asked 95.2k views
2 votes
Write code using the range function to add up the series 20,30,40,... 90 and print the resulting sum each step along the way.

1 Answer

6 votes

Final answer:

To print incremental sums of the series 20, 30, ... 90, initialize a sum variable, iterate over the series using range(20, 91, 10), and print the sum in each step.

Step-by-step explanation:

To add up the series 20, 30, 40, ... 90 and print the resulting sum at each step using Python's range function, you can use the following code:

sum = 0
for i in range(20, 91, 10):
sum += i
print(f'Sum up to {i}: {sum}')

This code initializes a variable sum to 0 and then iterates over the numbers 20 to 90 in increments of 10 using the range function. In each iteration, the number i is added to the sum, and the result is printed out.

To add up the series 20, 30, 40,... 90 using the range function in Python, you can use a for loop and the range function to generate the numbers in the series. Here's an example:

sum = 0

for i in range(20, 100, 10):

sum += i

print(sum)

In this code, we initialize the sum variable to 0. Then, we use the range function with a step of 10 to generate the numbers in the series. We add each number to the sum and print the resulting sum at each step.

No related questions found