Articles

# Program to find sum of n natural numbers in python

In this Python programming guide, we are going to learn:

• write a program to find the sum of n natural numbers in python

### Python program to find sum of n natural numbers

The python program to find sum of n natural numbers using for loop is as follows:

``````# Owner : TutorialsInhand Author : Devjeet Roy

num = int(input("Enter a natural number: "))
sum_natural = 0

if num < 1:
print("Wrong Input.")
else:
for i in range(num+1):
sum_natural += i

print("The sum is=",sum_natural)``````

The output of program to calculate sum of first n natural numbers in python is as follows:

``````PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a natural number: 10
The sum is= 55``````

1. The natural numbers begins from 1 and goes to positive infinity.

2. Here, we take the user input and convert it to integer data type. This is the upper limit of our range program.

3. We find the sum of numbers from 1 upto the user input and display the result on the terminal.

Program to find sum of n natural numbers in python snapshot: Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com 