Python Program to print digit pattern
The program must accept an integer N as the input. The program must print the desired pattern as shown in the example input/ output.
Examples:
Input : 41325
Output :
|****
|*
|***
|**
|*****
Explanation: for a given integer print the number of *’s that are equivalent to each digit in the integer. Here the first digit is 4 so print four *sin the first line. The second digit is 1 so print one *. So on and the last i.e., the fifth digit is 5 hence print five *s in the fifth line.Input : 60710
Output :
|******
|
|*******
|*
|
Approach
Read the input
For each digit in the integer print the corresponding number of *s
If the digit is 0 then print no *s and skip to the next line
# function to print the pattern def pattern(n): # traverse through the elements # in n assuming it as a string for i in n: # print | for every line print("|", end = "") # print i number of * s in # each line print("*" * int(i)) # get the input as string n = "41325"pattern(n) |
|**** |* |*** |** |*****
Recommended Posts:
- Python program to print checkerboard pattern of nxn using numpy
- Python 3 | Program to print double sided stair-case pattern
- Program to print the given Z Pattern
- Program to print the pattern 'G'
- Program to print the pattern "GFG"
- Program to print pattern
- Program to print the pattern ‘D’
- Program to print the given H Pattern
- Program to print pyramid pattern
- Program to print numeric pattern
- Program to print numeric pattern | Set - 2
- Program to print interesting pattern
- Program to print Crown Pattern
- Program to print a rectangle pattern
- Program to print number pattern
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



