Computer Science, asked by josephfranky980, 7 months ago

write a program to print sum of all the numbers from 31 to 72​

Answers

Answered by Equestriadash
8

We'll be using a for loop.

The following codes will have to be typed in script mode, saved and then executed.

CODE:

s = 0

for i in range(31, 73):

   s = s + i

print(s, "is the sum of the numbers from 31 to 72.")

OUTPUT:

2163 is the sum of the numbers from 31 to 72.

You'll first have to assign a variable. After doing so, you'll have to input the range of numbers.

Syntax of range is: range(start, stop, step)

  • Start - the value the series must start from.
  • Stop - the value the series must end at.
  • Step - the value by how much the series needs to skip each time.

Always note that once you've entered the stop value, the series always stops at a value before it. Hence the reason I typed 73 instead of 72.

Similar questions