File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 11# Program to accept a list of words and return the length of the longest word.
22
3+ # Function to find the ength of the longest word
34def longest_word (words ):
4- longest = 0
5- for word in words :
6- if len (word ) > longest :
7- longest = len (word )
8- longest_word = word
9- print ("Longest word is" ,longest_word )
10- print ("Length of longest word is" ,longest )
5+ longest = 0 # Initialize the longest word length to 0
6+ for word in words :
7+ if len (word ) > longest : # If the length of the current word is greater than the longest word length
8+ longest = len (word ) # Set the longest word length to the length of the current word
9+ longest_word = word # Set the longest word to the current word
10+ print ("Longest word is" ,longest_word ) # Print the longest word
11+ print ("Length of longest word is" ,longest ) # Print the length of the longest word
1112
12- print ("Enter a list of words separated by spaces: " )
13- words = input ().split ()
14- longest_word (words )
13+ print ("Enter a list of words separated by spaces: " )
14+ words = input ().split () # Get the list of words from the user
15+ longest_word (words ) # Function call
You can’t perform that action at this time.
0 commit comments