Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Predict the output of the Python code given below:

Text1="XYZ-456"

Text2=""

I=len(Text1)-1

while I>=0:

    if Text1[I]>="0" and Text1[I]<="9" :

        Val=int(Text1[I])

        Val=Val*2

        Text2=Text2+str(Val)

    elif Text1[I]>="A" and Text1[I]<="Z" :

        Text2= Text2+(Text1[I-1])

    else:

        Text2=Text2+"*"

    I-=1

print (Text2)

Answer:

Answer by student

The output of the Python code is 12108*YX6 .

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.