liveBook · Manning

Vowel

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

A vowel is a speech sound or alphabetic letter produced without significant obstruction of airflow, including a, e, i, o, and u in this context.

A vowel is a speech sound or letter produced with relatively open airflow. For these Python exercises, the vowel set is the lowercase string “aeiou”; a word’s first character determines whether to use “a” or “an.” section 2.1.10 section 2.1.11

Classify a word’s initial character incrementally:

  • Index the first character with word[0]; Python starts sequence indexes at zero. section 2.1.7
  • Normalize case with word[0].lower() so uppercase input needs only one comparison. section 2.1.10
  • Test membership with word[0].lower() in 'aeiou' instead of chaining five equality comparisons. section 2.1.10
  • Choose an article with 'an' if the test is true, else 'a'; this deliberately ignores pronunciation exceptions such as “honor” and “union.” section 2.1.11

Choosing an article

For word = 'OCTOPUS', word[0].lower() is 'o', and 'o' in 'aeiou' is True, so article becomes 'an'. For “narwhal,” it becomes “a.” The result can be inserted into “Ahoy, Captain, an octopus off the larboard bow!” section 2.0 section 2.3.3

Replacing vowels

A second exercise accepts text and a validated -v or --vowel option, then replaces every vowel while preserving input case: “APPLES AND BANANAS” with -v i becomes “IPPLIS IND BININIS.” section 8.0 section 8.3.1

Avast, you corny-faced gollumpus! Ye are barrelman for this watch. D’ye ken what I mean, ye addle-pated blunderbuss?! Ah, landlubber ye be! OK, then, you are the lookout in the crow’s nest--the little bucket attached to the top of a mast of a sailing ship. Your job is to keep a lookout for interesting or dangerous things, like a ship to plunder or an iceberg to avoid. When you see something like a narwhal, you are supposed to cry out, “Ahoy, Captain, a narwhal off the larboard bow!” If you see an octopus, you’ll shout “Ahoy, Captain, an octopus off the larboard bow!” (We’ll assume everything is “off the larboard bow” for this exercise. It’s a great place for things to be.)

Use the lookout scenario to connect vowel classification with the concrete “a narwhal” and “an octopus” outputs. section 2.0

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Explains indexing, case normalization, membership tests, conditional expressions, and replacement, while deferring pronunciation-aware rules.
Examples
Demonstrates narwhal, octopus, uppercase input, article selection, vowel substitution, consonant filtering, and rhyming-word generation.
What it assumes
Assumes basic Python strings and variables while teaching indexing, comparisons, membership, branching, argument validation, and file-input handling.
What you can do after
Build it from scratch as a tested Python program that classifies initial letters, selects articles, or replaces vowels in text.
How it connects
Connects string indexing, string methods, membership testing, conditional expressions, list comprehensions, filtering, and regular expressions.

Also explained in

Compare how 2 books explain vowel →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.