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

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz