livepython.net

105. Python Program to Count the Words in a Sentence

EasySplit and join

Overview

Turn a sentence into a list of words, then count the list.

Problem Statement

Read a sentence and print how many words it has. Words are separated by one or more spaces, and there may be spaces at the ends. For example, for Python is fun:

Words: 3

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One line of text. Example:

Python is fun

Output

The output for that example:

Words: 3

The tests try 4 different inputs, including one with extra spaces.

Learn this firstChapter 12 · Python split() and join(): Strings to Lists and Back
solution.py
# write your code here

EXPECTED OUTPUT

1Words: 3

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.