Answer to Question #260626 in Python for umesh

Question #260626

No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers.


Let’s save some time by creating a program to do the calculation for you!


Take a number N as input and output the sum of all numbers from 1 to N (including N).


Sample Input

100


Sample Output

5050


Explanation: The sum of all numbers from 1 to 100 is equal to 5050.


1
Expert's answer
2021-11-03T04:22:09-0400
n = int(input())
sum = 0
for i in range(1, n + 1):
    sum += i
print(sum)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog