Computer Science
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!')
Python Funda
13 Likes
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.
Answered By
4 Likes
Related Questions
How many times will the following for loop execute and what's the output?
for i in range(-1, 7, -2): for j in range (3): print(1, j)
How many times will the following for loop execute and what's the output?
for i in range(1,3,1): for j in range(i+1): print('*')
Is the loop in the code below infinite? How do you know (for sure) before you run it?
m = 3 n = 5 while n < 10: m = n - 1 n = 2 * n - m print(n, m)
Write a program to print one of the words negative, zero, or positive, according to whether variable x is less than zero, zero, or greater than zero, respectively