Project Level 1: Beginner
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
Project Description
This project involves creating a program that takes a sentence as input and counts the number of words in that sentence. The program will also identify the longest word in the sentence.
Learning Benefits
This project will help you practice string manipulation and introduce you to list operations in Python. By counting words and finding the longest word, you will enhance your problem-solving skills and gain confidence in handling text data.
How the Program Works
The program prompts the user to enter a sentence. Then, the program returns a message followed by the number of words in the sentence given by the user. In the last line, the program also displays the word that contains more letters in the given sentence.
Prerequisites
Required Libraries: No libraries are required.
Required Files: No files are required.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Once you code the project, compare it with our two solutions given in the button below.
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')