Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
The reason is that, even though the iteration is not yet finished or in other words the other names of 2nd 3rd and so on... scientist is not iterated. For example: Becky Joan Fred Trey James Then "Becky" will be the first iteration, then since their first names are not matched, The "else" statement will be executed and will skip the next iterations: So here, I've used "for-else" loop. It will first iterate each names. And IF it match with at least 1 name, it will print "Compare Notes" and will break the loop. And if the loop breaks, the "else" will not be executed. If there is no match, the loop will not break and the "else" will be executed. Although there are more ways other than using "for-else" loop like what ♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ did If you need more explanation, please feel free to ask. Thanks! https://code.sololearn.com/ca15A9a6A1a1
20th Jan 2021, 2:13 AM
noteve
noteve - avatar
0
??
19th Jan 2021, 6:14 PM
Abhay
Abhay - avatar
0
Ah ok yurkovsky since I can't access that question can you list an example of inputs and expected output ?
19th Jan 2021, 6:22 PM
Abhay
Abhay - avatar
0
names = input().split(" ") name = input() #using IN list initials = [i[0] for i in names] print("Compare notes" if name[0] in initials else "No such luck")
25th Oct 2021, 8:16 AM
Mateo González Bufi
Mateo González Bufi - avatar
0
I think the problem is that your loop is updating the “result” variable all the way through, so if you get a False on the IF statement it will overwrite with “No such luck” even if you had a True result before.
25th Oct 2021, 8:22 AM
Mateo González Bufi
Mateo González Bufi - avatar