Program to find sum of first n natural numbers in Python
In the python programming article, we are going to learn
-
program to find the sum of n natural numbers in python
Program to find the sum of n natural numbers in Python
The program is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
n = int(input("Enter the value of n: "))
sum_of_natural_nos = 0
for i in range(1,n+1):
sum_of_natural_nos += i
print("Sum of first {} natural number:".format(n),sum_of_natural_nos)
The output of the program is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the value of n: 5
Sum of first 5 natural number: 15
Few important tips about the program
1. Natural numbers start from 1 and continues upto positive infinity.
2. We have iterated upon the n natural numbers and added them up to find the sum.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Oct 13,2022