2 Comments
User's avatar
Mathew Holland's avatar

My solution:

sentence = input("Enter a sentence\n>> ")

longest_word = ''

sentence = sentence.split(' ')

for word in sentence:

if len(word) > len(longest_word):

longest_word = word

print(f"The number of words in the sentence is: {len(sentence)}\n"

f"The longest word in the sentence is '{longest_word}'")

Expand full comment
Marco's avatar

Esta es mi solucion:

sentence = input("Enter a sentece: ")

words = sentence.split()

number_words = len(words)

longest_word = ''

longest_length = 0

for word in words:

if len(word) > longest_length:

longest_word = word

longest_length = len(word)

print(f'The number of words in sentence is: {number_words}')

print(f'The longes word is "{longest_word}", with {longest_length} characters')

Expand full comment