Python Core - ex 62 - Longest Word | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python Core - ex 62 - Longest Word

Hi all, what is wrong here, for some reason in Python 3 it works but with their taste case’s it always fails and it takes the las word from the list txt = input() #your code goes here new_bla = txt.split(" ") i = 0 ln = ['t'] while i < len(new_bla): if len(new_bla[i]) > len(ln): ln.clear() ln.append(new_bla[i]) i=i+1 print(ln)

7th Jul 2022, 12:26 PM
Samuel Fodorean
Samuel Fodorean - avatar
4 Answers
+ 3
Samuel Fodorean , you have been very close to a correct solution. so i would like to present you the 2 issues of your code. you can fix it, and it will run. >> i find it important for you to know why your code has not been passed the test cases. see the slightly reworked code in the file: https://code.sololearn.com/cGm1ony5cWY0/?ref=app
7th Jul 2022, 5:36 PM
Lothar
Lothar - avatar
+ 1
Thanks
7th Jul 2022, 6:53 PM
Samuel Fodorean
Samuel Fodorean - avatar
0
Print this in ex: txt = input() # your code goes here list = max(txt.split(" "), key = len) Print(list)
7th Jul 2022, 1:03 PM
Douae Andaloussi
Douae Andaloussi - avatar
0
Thanks
7th Jul 2022, 1:36 PM
Samuel Fodorean
Samuel Fodorean - avatar