Discussion about this post

User's avatar
Adi's avatar

print("Enter a Sentence:")

User_input = input()

word_count = len(User_input.split(' '))

list1 = User_input.split(' ')

bigword = ""

for x in list1:

word = ''

if len(x) > len(word):

word = x

bigword = word

print("The total word count is ", word_count)

print("The longest word in the sentence is",bigword)

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}'")

1 more comment...

No posts

Ready for more?