CBSE Class 12 Computer Science Question 93 of 105

Python Revision Tour — Question 19

Back to all questions
19
Question

Question 5

Find and write the output of the following python code:

for Name in ['Jay', 'Riya', 'Tanu', 'Anil'] :
    print (Name)
    if Name[0] == 'T' :
        break
    else :
        print ('Finished!')
print ('Got it!')
Answer
Output
Jay
Finished!
Riya
Finished!
Tanu
Got it!
Explanation

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.