0

Onto the longest word project, it passed all cases except 4 so I didn't pass it... Help? Code is below.

txt = input() words=txt.split(" ") #your code goes here long_word_len =len(words[0]) for i in words: word_len=len(i) if word_len>long_word_len: long_word_len=word_len current=i print(current)

18th Jan 2021, 5:11 AM
Michele Rene Machado
Michele Rene Machado - avatar
2 Respostas
+ 4
Try to think what will happen in your code if the first word, that is words[0], is the longest
18th Jan 2021, 5:35 AM
XXX
XXX - avatar
+ 2
Aside from XXX has given, you may also want to declare that "current" variable first outside the for loop so it would also have a default value like long_word_len.
18th Jan 2021, 5:50 AM
noteve
noteve - avatar