+ 1
why does it give an indexerror
7 Antworten
+ 3
Майкл Дориан To print the bigger word, put this in the body of the while
while c < len(a):
b = len(a[c])
if b > n:
n = b
cm = c
c += 1
+ 4
txt = "Sololearn is cool platform"
words = txt.split()
for a in words:
print(a)
Easy way to access each word from the list of words.
---------------------------------------------------------------------
[Longest word in the list of words]
txt = input() or "Sololearn is cool"
words = txt.split()
longest = ""
for word in words:
if len(word) > len(longest):
longest = word
print("longest word is", longest, "with length of", len(longest))
+ 1
c<len(a) instead of c<=len(a).
if you do c<=len(a) you are checking for value at index 2 as well if for example the input is "hello world".
+ 1
Майкл Дориан replace while c <= len(a): with while c < len(a):
0
because the index is out of range. what are you trying to do?
0
I want to get the longest word in a sentence
0
Thank you