Wednesday, 7 April 2021

The python program to read string and print longest word

Write a program in python to read string and print longest word and its position:

word=input('enter a value')
words=word.split()
print(words)
length=len(words)
maximum=0
pos=0
for i in range(length):
    l=len(words[i])
    if l>maximum:
        maximum=l
        pos=i   
print('longest word is',words[pos])
print('Number of characters in longest word  is',maximum)
print('Position on longest word is ',pos+1)