27th Apr 2021, 8:54 AM
Майкл Дориан
Майкл Дориан - avatar
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
27th Apr 2021, 9:10 AM
Erlénio.RS
Erlénio.RS - avatar
+ 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))
27th Apr 2021, 9:08 AM
RKK
RKK - avatar
+ 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".
27th Apr 2021, 8:58 AM
Abhay
Abhay - avatar
+ 1
Майкл Дориан replace while c <= len(a): with while c < len(a):
27th Apr 2021, 9:02 AM
Erlénio.RS
Erlénio.RS - avatar
0
because the index is out of range. what are you trying to do?
27th Apr 2021, 8:57 AM
Slick
Slick - avatar
0
I want to get the longest word in a sentence
27th Apr 2021, 9:00 AM
Майкл Дориан
Майкл Дориан - avatar
0
Thank you
27th Apr 2021, 9:08 AM
Майкл Дориан
Майкл Дориан - avatar