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) ----------------------------------------------------------------
6 Respostas
+ 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
0
can you please name the task?
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
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)
0
a = input().split()
length= []
for i in a:
length.append(len(i))
x=max(length)
y=length.index(x)
print(a[y])
0
Oo, my problem was solving with predefined max. Thank you all for your input.