top of page

11) Python Program to Find the Sum of Natural Numbers

Natural numbers:

As the name specifies, a natural number is the number that occurs commonly and obviously in the nature. It is a whole, non-negative number.

Some mathematicians think that a natural number must contain 0 and some don't believe this theory. So, a list of natural number can be defined as:

  1. N= {0, 1, 2, 3, 4, .... and so on}  

  2. N= {1, 2, 3, 4, .... and so on}  

See this example:

back.png

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)  

bottom of page