Write a program that gets an integer , which its number of digits is not specified. then print each digit n times if n is the digit itself

How can I solve this problem?
like this:
6041
6: 666666
0:
4: 4444
1: 1
I just know that for separating numbers we should do this, I think:

num = int(input)
while num > 0:
res = num // 10
num = num % 10

>Solution :

One way to do it is to keep the number as a string, then in a loop convert the first digit to an int, print it n times, then remove it. Repeat the loop until the string is empty:

num = input("Input a number: ")
while len(num) > 0:
    digit = num[0]
    for i in range(int(digit)):
        print(digit, end="")
    num = num[1:]

Leave a Reply