Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

String-7th program, multiplication

# i/p: a4b3c2
#o/p : aaaabbbcc
#convert string to list
#get the odd indexes as it contains no., convert it to no., multiply it with even 
s="a4b3c2"
l1=[]
i=0
for x in s:
    l1.append(s[i])
    i=i+1
print(l1)

i=1
l2=[]
for x in range(0,len(s)):
    if(i+2)<len(s)+2: #to check last index, i=5, our +2 logic may throw index out of range
        l2.append(int(s[i]))
        i=i+2
print(l2)
i=0
j=0
res=""
for x in s:
    if(i+2)<len(s)+2:
        res=res+l1[i]*l2[j]
        i=i+2
        j=j+1
print(res)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.