In the previous article, we have discussed Python Program to Print Series 6, 11, 21, 36, 56…n
Given a number N and the task is to print the series (1,22,333,4444…N) for the given number N in Python.
Examples:
Example1:
Input:
Given Number = 5
Output:
The above series till the given number{ 5 } is : 1 22 333 4444 55555
- Python Program to Print Series 0 2 6 12 20 30 42…N
- Python Program to Find Sum of Series 5^2 + 10^2 + 15^2 +…..N^2
- Python Program to Print Series 6, 9, 14, 21, 30, 41, 54 … N
Example2:
Input:
Given Number = 8
Output:
The above series till the given number{ 8 } is : 1 22 333 4444 55555 666666 7777777 88888888
Program to Print Series 1,22,333,4444…n in Python
Below are the ways to print the series (1,22,333,4444…N) for the given number N in Python.
Method #1: Using For Loop (Static Input)
Approach:
- Give the number N as static input and store it in a variable.
- Loop till the given number using the for loop.
- Inside the For loop, Iterate till the above iterator value of the parent for loop using another Nested For loop(Inner For loop).
- Print the iterator value of the parent for loop separated by spaces.
- Print the space by using the end keyword.
- The Exit of the Program.
Below is the implementation:
# Give the number N as static input and store it in a variable. gvn_numb = 5 print("The above series till the given number{", gvn_numb, "} is :") # Loop till the given number using the for loop. for itr in range(gvn_numb+1): # Inside the For loop, Iterate till the above iterator value of the parent for loop # using another Nested For loop(Inner For loop). for m in range(itr): # Print the iterator value of the parent for loop separated by spaces. print(itr, end="") # Print the space by using the end keyword. print(end=" ")
Output:
The above series till the given number{ 5 } is : 1 22 333 4444 55555
Method #2: Using For loop (User Input)
Approach:
- Give the number N as user input using the int(input()) function and store it in a variable.
- Loop till the given number using the for loop.
- Inside the For loop, Iterate till the above iterator value of the parent for loop using another Nested For loop(Inner For loop).
- Print the iterator value of the parent for loop separated by spaces.
- Print the space by using the end keyword.
- The Exit of the Program
Below is the implementation:
# Give the number N as user input using the int(input()) function and # store it in a variable. gvn_numb = int(input("Enter some Random Number = ")) print("The above series till the given number{", gvn_numb, "} is :") # Loop till the given number using the for loop. for itr in range(gvn_numb+1): # Inside the For loop, Iterate till the above iterator value of the parent for loop # using another Nested For loop(Inner For loop). for m in range(itr): # Print the iterator value of the parent for loop separated by spaces. print(itr, end="") # Print the space by using the end keyword. print(end=" ")
Output:
Enter some Random Number = 8 The above series till the given number{ 8 } is : 1 22 333 4444 55555 666666 7777777 88888888
Practice Python Program Examples to master coding skills and learn the fundamental concepts in the dynamic programming language Python.