Skip to main content

Python Program to find sum of n natural numbers

 Sum of n natural numbers

Natural number :

All positive integers are natural numbers.

Input :

enter n value 20

Output : 

sum of 20 natural numbers is 210

 Python Program to find sum of n natural numbers

#program to find n natural numbers
n=int(input("enter "))
nsum=0
if n >1:
    for i in range(1,n+1):
        nsum+=i
    print(f"sum of {n} natural numbers is {nsum}")
else:
    print("enter a natural number")

Output :

enter 20
sum of 20 natural numbers is 210

Output :

enter -3
enter a natural number

Comments