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 integers, output the number of * that corresponds to each digit in the integer. Here the first digit is 4, so print four * in the first line. The second digit is 1, so print *. So the last one, ie. the fifth digit is 5, so print five * s on 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)
Output:
|**** |* |*** |** |*****
Alternate solution that takes integer as input :
n = 41325 x = [] while n>0: x.append(n%10) n //= 10 for i in range(len(x)-1,-1,-1): print('|'+x[i]*'*') # code contributed by Baivab Dash
Output:
|**** |* |*** |** |*****
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.