>> Module 02 / Day 20 / Friday

Quiz & Word Counter

Mini-Quiz 2, then build & ship
End of week 4. A quick 15-minute quiz to lock in the week's skills — then your second mini-project, a tool that measures text.
Quiz
15 min · 09:00–09:15
Lab
60 min · Word Counter
Module
M2 · Python in Practice
DAY 20 / 40
>> Today's plan

Three parts to the morning

  1. Mini-Quiz 2 — 15 minutes, this week's string & list skills
  2. Quick recap of the week (D16–D19)
  3. Design the Word Counter together
  4. The three measurements — characters, words, lines
  5. Lab — build it and ship a PR
>> 09:00 – 09:15 · Mini-Quiz 2

15 minutes · pen & paper

No computers. Predict outputs and write tiny snippets. Covers everything from Day 16 to Day 19.

WHAT'S ON IT
  • • String methods — split / join / strip / replace
  • • Slicing — what does s[1:4] / s[::-1] give?
  • • List verbs — append / remove / pop / in
  • • The dedupe pattern from yesterday
SAMPLE QUESTION
predict.py
s = "  Hello World  "
print(s.strip().lower().split())
# Write the exact output ↓
>> The week in one glance · D16 – D19

Everything you collected this week

D16 · STRING METHODS

split, join, strip, lower, replace — reshape text.

D17 · SLICING

s[i], s[a:b], s[::-1] — reach inside text.

D18 · LIST OPS

append, remove, pop, in, sort — manage collections.

D19 · COMBINE

Plan in steps; the dedupe pattern; tools working together.

>> Design first

What does a Word Counter measure?

Three numbers from one block of text. Each has a one-line trick you already know.

Characters

Just the length of the string.

len(text)

Words

Split on whitespace, count the pieces.

len(text.split())

Lines

Split on the newline character.

len(text.splitlines())

>> The core, in full

The whole counter

word_counter.py
text = input("Paste your text: ")

chars = len(text)
words = len(text.split())
lines = len(text.splitlines())

print(f"Characters: {chars}")
print(f"Words:      {words}")
print(f"Lines:      {lines}")

# Bonus — the longest word, using a list + sort:
longest = sorted(text.split(), key=len)[-1]
print(f"Longest word: {longest}")
>> 11:00 – 12:00 · Mini-project

Today's lab — Word Counter

CORE
Count it all

Read a paragraph and report characters, words, and lines, each on its own labelled line.

★ STRETCH
Go further

Add the longest word, the average word length, and characters excluding spaces.

>> End of Week 4 · Day 20

Halfway to the capstone

  • ✓ You can reshape, slice, and search text and lists with confidence.
  • ✓ You've shipped two real tools — a deduplicator and a word counter.
  • ✓ Day 20 of 40 — exactly halfway through the course.
01 / 8
←/→ navigate   F fullscreen   Ctrl/⌘+P save as PDF