Monday, 28 June 2021

Python program to Expand Alphabet

Expand Alphabets

This program takes a string Str as input. The input string contains a sequence of an integer followed by an alphabet. The output must print the alphabets as many times as the related integer on its left.

Input

1a2b

Output

abb

Input 

a3r

In this case, the output will be rrr.

If only the input is given in the correct format, the output will be displayed. If the input is incorrect then no output is produced.

Incorrect Input

a3

PROGRAM

Str = input("Enter the input string:")

num = ""

l=len(Str)

i=0

while (i < l):

    if (Str[i] >= '0' and Str[i] <= '9'):

        while (i < l and Str[i] >= '0' and Str[i] <= '9' ):

            num=num+Str[i]

            i=i+1

        num=int(num)

        if (i < l):

            while (num > 0):

                print(Str[i],end="")

                num=num-1

    i=i+1

    num=""


OUTPUT

Enter the input string:100q2w

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqww


Enter the input string:a3r

rrr