
- 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
Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
When it is required to read a number and print the pattern of summation of natural numbers, a simple ‘for’ loop can be used.
Below is a demonstration of the same −
Example
my_num = int(input("Enter a number... ")) for j in range(1,my_num+1): my_list=[] for i in range(1,j+1): print(i,sep=" ",end=" ") if(i<j): print("+",sep=" ",end=" ") my_list.append(i) print("=",sum(my_list)) print()
Output
Enter a number... 5 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15
Explanation
A number is taken as input from the user.
This number is iterated over.
An empty list is defined.
Another ‘for’ loop is initiated.
The separator is specified as ‘’.
If the value of inner iterator is less than value of outer iterator, the ‘+’ is used.
These values are appended to the empty list.
Their sum is computed and displayed as the output.
- Related Articles
- Golang Program to Read a Number (n) and Print the Natural Numbers Summation Pattern
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Goland Program to Read a Number (n) And Print the Series "1+2+…..+n= "
- Python program to print a checkboard pattern of n*n using numpy.
- Python Program to Read Two Numbers and Print Their Quotient and Remainder
- PHP program to print the number pattern
- Find m-th summation of first n natural numbers in C++
- Program to print ‘N’ alphabet using the number pattern from 1 to n in C++
- Python program to print check board pattern of n*n using numpy
- Program to print a pattern of numbers in C++
- Python Program to print the pattern ‘G’
- Java Program to Print Spiral Pattern of Numbers
- Golang Program to Print Spiral Pattern of Numbers
- Program to print number pattern in C
- Program to find number of magic sets from a permutation of first n natural numbers in Python

Advertisements