Longest word problem python test case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Longest word problem python test case

Hello, I cant find what I am missing for last test case ,any suggestions? ---------------------------------------------------------------------------------------- txt = input() #your code goes here txt=txt.split() #print(txt) max=len(txt[0]) word='' for i in txt: if max<len(i): max=len(i) word=i print(word) ----------------------------------------------------------------

15th Jun 2021, 11:23 AM
Frano Piskulić
Frano Piskulić - avatar
6 Answers
+ 1
Here is the information in the task. Its from Python Core More Types 11. Code Project It only recommends using split. ------------------------------------------- Longest Word Given a text as input, find and output the longest word. Sample Input this is an awesome text Sample Output awesome
15th Jun 2021, 11:30 AM
Frano Piskulić
Frano Piskulić - avatar
0
can you please name the task?
15th Jun 2021, 11:27 AM
SammE
SammE - avatar
0
Is the word variable containing a single quote or a double quote and anyways you don't need to initialize variable before using it in Python
15th Jun 2021, 11:28 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
txt = input() txt=txt.split(" ") max=len(txt[0]) for i in txt: if max<len(i): max=len(i) word=i print(word)
15th Jun 2021, 11:32 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
a = input().split() length= [] for i in a: length.append(len(i)) x=max(length) y=length.index(x) print(a[y])
15th Jun 2021, 11:34 AM
SammE
SammE - avatar
0
Oo, my problem was solving with predefined max. Thank you all for your input.
15th Jun 2021, 11:48 AM
Frano Piskulić
Frano Piskulić - avatar