#
Python-Sum of Series 1+2+3+…+10

Write a program to compute the sum of the series 1+2+3+… +10

# Sum of Series
# 1 + 2 + 3 + 4 + 5 + 6 + .... + 10
sum = 0
#try putting a comment symbol in the above line and observe the error produced
#what is the reason behind this error?
#Although we want sum of first 10 numbers, we will generalise and take the sum
#upto first n numbers.
#What is the largest value of n that will give a correct output?
#Ofcourse we can also find the sum by the formula sum = n(n+1)/2
n = int(input("Enter a number "))
for i in range(n + 1):
sum = sum + i
print("Sum of series is : ", sum)
#EOProgram

### Share this with your friends:

### Like this:

Like Loading...