KnowledgeBoat Logo
|

Computer Science

Find and write the output of the following python code:

for Name in ['Jayes', 'Ramya', 'Taruna', 'Suraj'] :
    print (Name)
    if Name[0] == 'T' :
        break
    else :
        print ('Finished!')
print ('Got it!')

Python

Python Funda

45 Likes

Answer

Jayes
Finished!
Ramya
Finished!
Taruna
Got it!

Working

The for loop iterates over each name in the list and prints it. If the name does not begin with the letter T, Finished! is printed after the name. If the name begins with T, break statement is executed that terminates the loop. Outside the loop, Got it! gets printed.

Answered By

11 Likes


Related Questions