231,520 views
19 votes
19 votes
Write code using the range function to add up to the series 20,30,40, ...90 and print the resulting sum each step along the way

Write code using the range function to add up to the series 20,30,40, ...90 and print-example-1
User Vijay Agrawal
by
2.9k points

1 Answer

18 votes
18 votes

Answer:

Code:

range_sum = 0

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

range_sum += x

print(range_sum)

Step-by-step explanation:

Declare variable (we'll use it to keep track of the sum):

range_sum = 0

Start a loop with the range function (x is the current number, 20, 100 are the numbers to start and stop by and 10 is the number to increase by):

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

Add the current number to the sum and print it:

range_sum += x

print(range_sum)

User Chris Farr
by
3.1k points