Computer Science, asked by palakaggarwal2004, 7 months ago

write programs in python to sum the series using while loop
1. 1+2+3+4+5+....+n

Answers

Answered by anindyaadhikari13
11

Question:-

Write a Python program to find the sum of the series.

1+2+3+4+5+6+....+n

Program:-

Here is your program.

n=int(input("Enter the number of terms: "))

i=1

s=0

while(i<=n):

s=s+i

i=i+1

print("Sum is: ",s)

Output:-

Enter the number of terms: 10

Sum is: 55.

Answered by SaurabhJacob
5

The program is in python for the given series of the sum,

n=int(input("Enter the value of 'n' = "))

sum = 0

for i in range(1,n+1):

   sum+=i

print("Sum of the series is",sum)

In the above program,

  • Firstly the input is being inputted to the variable n, for taking the last value of the series.
  • After that, a variable sum is intiated to 0 to store the in-between result of the sum after every iteration of the for loop.
  • After that, the loop is made to run according to the given series.
  • And Finally, the print statement is used to print the calculated value of the sum in the for loop.
Similar questions