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

Enter a String :python is very easy language

Longest Word: language

Length of the Word: 8

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad