Today we are going to share a Python Program to Read a List of Words and Return the Length of the Longest One. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python Program to Read a List of Words and Return the Length of the Longest One.
To increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 | a=[] n= int(input("Enter the number of elements in list:")) for x in range(0,n): element=input("Enter element" + str(x+1) + ":") a.append(element) max1=len(a[0]) temp=a[0] for i in a: if(len(i)>max1): max1=len(i) temp=i print("The word with the longest length is:") print(temp) |
Enter the number of elements in list:3
Enter element1:”Bangalore”
Enter element2:”Mumbai”
Enter element3:”Delhi”
The word with the longest length is:
Bangalore
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.