- 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

# Python Program to Read a Number n And Print the Series "1+2+…..+n= "

When it is required to display the sum all the natural numbers within a given range, a method can be defined that uses a loop to iterate over the elements, and returns the sum of these numbers as output.

Below is a demonstration of the same −

## Example

def sum_natural_nums(val): my_sum = 0 for i in range(1, val + 1): my_sum += i * (i + 1) / 2 return my_sum val = 9 print("The value is ") print(val) print("The sum of natural numbers upto 9 is : ") print(sum_natural_nums(val))

## Output

The value is 9 The sum of natural numbers upto 9 is : 165.0

## Explanation

A method named ‘sum_natural_nums’ is defined that takes a number as parameter.

A sum value is defined as 0.

A loop is iterated over the number passed as a parameter.

The sum is incremented every time a number is encountered.

This is returned as output.

The value for number of natural numbers whose sum needs to be found is defined.

The method is called by passing this number as a parameter.

The relevant output is displayed on the console.

- Related Questions & Answers
- Goland Program to Read a Number (n) And Print the Series "1+2+…..+n= "
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Golang Program to Read a Number (n) and Print the Natural Numbers Summation Pattern
- Golang Program to Read a Number (n) and Compute (n+nn+nnn)
- Python Program to Read Two Numbers and Print Their Quotient and Remainder
- Java program to print Fibonacci series of a given number.
- Python Program for Print Number series without using any loop
- Print Number series without using any loop in Python Program
- Python Program to Input a Number n and Compute n+nn+nnn
- Python program to print a checkboard pattern of n*n using numpy.
- Write a Golang program to print the Fibonacci series
- Java program to print a Fibonacci series
- Python program to print number triangle
- Java program to print the fibonacci series of a given number using while loop
- Java Program to print Number series without using any loop

Advertisements