#WSQ04 – Sum of Numbers

Here are the instructions:

-Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

 

  1. I defined a formula which asks for the range of integers and then prints the sum of the numbers in that range. I first asked for the list of number between the lower and upper bound thanks to the formula range(). Notice that I wrote y+1 as Python3 does not include the upper bound. Secondly, I just needed to use the formula sum() for the range.
  2. Print everything and there you go!

 

-Just for fun, what is the mathematical formula to do this calculation?

Let n+1 be the number of integers between the two boundaries. The mathematical formula is

Sum=N+1(First + Last)/2

Leave a comment