A consonant is treated here as a non-vowel letter, such as b or n, identified by examining a word’s characters. The exercise uses the vowels a, e, i, o, and u as the comparison set; every other checked letter counts as a consonant. section 2.1.10 section 2.1.7
Classify consonants in Python by following a small sequence of string operations:
- Extract the first character with word[0], remembering that string indexes begin at zero. section 2.1.7
- Normalize case with lower() or upper() before comparing letters. section 2.1.10
- Test membership with char in 'aeiou'; a false result identifies the character as a consonant for this exercise. section 2.1.10 section 2.1.13
- For larger tasks, separate leading consonants from the remainder of a word and generate the consonant collection with a guarded comprehension or filter(). section 14.3.1
Choosing the article
A command-line program checks the first letter of narwhal and prints “Ahoy, Captain, a narwhal off the larboard bow!”; octopus produces “Ahoy, Captain, an octopus off the larboard bow!” section 2.0
Use the lookout scenario to connect consonant detection with choosing a or an in a complete output sentence. section 2.0

