Unit 3 Task 13 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 13: Word tally from a sentence

← Back to task


One possible program:

line = input("Enter a sentence: ")
words = line.split()
counts = {}

for word in words:
    counts[word] = counts.get(word, 0) + 1

for word in counts:
    print(word, ":", counts[word])