Count Words in Text
Medium
Write a function count_words(text) that takes a multi-line string (simulating file content) and returns the total number of words across all lines.
Input
A multi-line string.
Output
An integer total word count.
Example
Input
"Hello world\nThis is Python\nGoodbye"
Output
6
Split the text by whitespace (which handles newlines too) using text.split(), then count the resulting list length.
10 XP on solve
Back to lesson
Your Solution
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to submit your solution and earn XP.