Programming Examples

Python program to find the longest word present in the sentence along with its length


Write a code in Python to enter a sentence and display the longest word present in the sentence along with its length.

Sample Input: WE ARE LEARNING PYTHON

Sample Output: The longest word : LEARNING

The length of the word : 8

wd='';nwd='';c=a=0
str=input("Enter a String :")
str=str+' '
p=len(str)
for i in range(0,p):
    if(str[i]==' '):
        a=len(wd)
        if(a>c):
            nwd=wd
            c=a
            a=0
        wd=""
    else:
      wd=wd+str[i]
print("Longest Word:",nwd)
print("Length of the Word:",c)
Output/ Explanation:

Enter a String :python is very easy language

Longest Word: language

Length of the Word: 8

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad