why does it give an indexerror | Sololearn: Learn to code for FREE!

+1

why does it give an indexerror

https://code.sololearn.com/c6HAD2R1tUYi/?ref=app

4/27/2021 8:54:00 AM

Майкл Дориан

7 Answers

New Answer

+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