Sum of Natural Numbers in Python
Here you will learn the source code to find the sum of natural numbers in python programming.
Natural Number : A natural number is a whole number greater than zero, such as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, etc.
Sum of Natural Numbers Formula
Program Code to find Sum of Natural Numbers in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #Python Program to Find the Sum of Natural Numbers # input number n = int(input("Enter a number : ")) sum = 0 i = 1 while i <=n: sum = sum + i i = i+1 # print sum print("The sum is", sum) |
Output
Enter a number : 9
The sum is 45
Check out our other Python Programming Examples