
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Find the Sum of Natural Numbers using Python?
You can use while loop to successively increment value of a variable i by one and adding it cumulatively.
s,i=0,0 n=10 while i<n: i=i+1 s=s+i print ("sum of first 10 natural numbers",s)
For loop is also used to loop over a range of natural numbers and add them cumulatively.
s=0 for i in range(11): s=s+i print ("sum of first 10 natural numbers",s)
Lastly using the built in function sum() also gives sum of a range of numbers
s=sum(range(11)) print ("sum of first 10 natural numbers",s)
- Related Articles
- How to Find Sum of Natural Numbers Using Recursion in Python?
- Java Program to Find the Sum of Natural Numbers using Recursion
- Haskell Program to Find the Sum of Natural Numbers using Recursion
- Golang Program to Find the Sum of Natural Numbers using Recursion
- C++ program to Find Sum of Natural Numbers using Recursion
- Java Program to Find Sum of Natural Numbers Using While Loop
- Java program to find the sum of n natural numbers
- Find the sum of first and even natural numbers.
- Find the sum of first $n$ odd natural numbers.
- 8085 program to find the sum of first n natural numbers
- How to Calculate the Sum of Natural Numbers in Golang?
- Program to find sum of first n natural numbers in C++
- The sum of the squares of three consecutive natural numbers is 149. Find the numbers.
- PHP program to find the sum of cubes of the first n natural numbers
- Java Program to Calculate the Sum of Natural Numbers

Advertisements