- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find sum of first N odd numbers in Python

Suppose we have a number n, we have to find the sum of the first n positive odd integers.

So, if the input is like n = 10, then the output will be 100, as the first 10 odd integers are [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] and its sum is 100.

To solve this, we will follow these steps −

- There is a nice observation, for first n odd numbers, the sum is always square of n.
- So to get the result, return n*n

## Example

Let us see the following implementation to get better understanding −

def solve(n): return n*n n = 10 print(solve(n))

## Input

10

## Output

100

- Related Questions & Answers
- Program to find the sum of first n odd numbers in Python
- Sum of square of first n odd numbers
- Program to find sum of first n natural numbers in C++
- 8085 program to find the sum of first n natural numbers
- Average of first n odd naturals numbers?
- Python Program for cube sum of first n natural numbers
- Python Program for Sum of squares of first n natural numbers
- Squared sum of n odd numbers - JavaScript
- Sum of first n natural numbers in C Program
- Java Program to cube sum of first n natural numbers
- PHP program to find the sum of cubes of the first n natural numbers
- Sum of squares of first n natural numbers in C Program?
- Sum of the first N Prime numbers
- Sum of sum of first n natural numbers in C++
- PHP program to find the sum of the 5th powers of first n natural numbers

Advertisements