for name in [‘Jayes’, ‘Ramya’, ‘Taruna’, ‘Suraj’]
print(name)
if(name[0]==’T’):
break
else:
print(‘Finished’)
print(‘Got it!’)
Answers
Answered by
3
Use this for Python?
or pj5.js
Answered by
9
Output:
Jayes
Finished!
Ramya
Finished!
Taruna
Got it!
Explanation:
Program:
for Name in ['Jayes', 'Ramya', 'Taruna','Suraj']:
print (Name)
if Name[0]== 'T':
break
else:
print ('Finished!')
print ('Got it!')
Let us understand the program.
for Name in ['Jayes', 'Ramya', 'Taruna','Suraj']: #It is a for loop.
print (Name) #This statement is used to print the Names.
#If the first character of the name is T, then the for loop will break.
if Name[0]== 'T':
break
#If the above condition fails, else statements will be executed.
else:
print ('Finished!') #This statement is used to print 'Finished!'.
#After execution of the for loop, following statement will be executed.
print ('Got it!') #This statement is used to print 'Got it!'.
Refer the attached image for the output.
Attachments:
Similar questions