97.2k views
5 votes
Write a program to read a sentence which is a single string. Then count the number of words in the sentence. The program will read in a string not one character at a time. Output: Enter the sentence : How are you The total count of words is : 3

1 Answer

3 votes

Answer:

The program in Python is as follows:

sentence = input("Sentence: ")

words = len(sentence.split())

print("Words:", words)

Step-by-step explanation:

This reads the sentence for the user

sentence = input("Sentence: ")

This counts the number of words

words = len(sentence.split())

This prints the number of words

print("Words:", words)

User Albert Alises
by
4.6k points