Program to Find Sum of Series Natural Numbers in Python

Program to Find Sum of Series Natural Numbers in Python. This program contains input capture, if else conditional statement and while loop. This is a basic program for Beginners, Class 11,12 and B Tech computer science students.

Program to Find Sum of Series Natural Numbers in Python

What is Natural Number ?

The natural numbers are those numbers used for counting and ordering.
N={1,2,3,4,5……so on}

Series that will get calculated?

If we input number as 10. Then 1+2+3+4+5+6+7+8+9+10 will be added.

Source code

num = int(input("Enter a number: "))  
  
if num < 0:  
   print("Enter a positive number")  
else:  
   sum = 0  
   # use while loop to iterate un till zero  
   while(num > 0):  
       sum += num  
       num -= 1  
   print("The sum is",sum)

Download Source code : For Download Click on the below Button

Stepwise Source code Explanation :

step 1 :Enter the number, which is last limit of sumation of natural number series
num = int(input(“Enter a number: “))
step 2 :If the number is not natural number
if num < 0:
print(“Enter a positive number”)
step .3 :If the number is natural, then the number added to sum
sum = 0 # use while loop to iterate un till zero
while(num > 0):
sum += num
num -= 1
step 4 :Print the sum
print(“The sum is”,sum)

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number: 120
The sum is 7260
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number: 10
The sum is 55
>>> 

Output explanation :

The input is captured.
Enter a number: 120
The sum of series of natural number up to number 120 is
The sum is 7260
Similarly for 10 sum is 55.

Conclusion:

The program is running fine.

Thank you for reading and learning from Program to Find Sum of Natural Numbers in Python post. This program contains input capture, if else conditional statement and while loop. This is a basic program for Beginners, Class 11,12 and B Tech computer science students.

Python Programs Archives – CS Study

Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study

Computer Science Practical file for class 12 Term-2 – CS Study

Leave a Comment

Your email address will not be published.