W WolfCode · CSC 141

Walkthrough: Count Vowels

例题: 数元音字母

≈ 8 min · python-strings python-loops · Open in WolfCode

The textbook's canonical counter pattern (TP §8.7), applied to vowels instead of a single letter.

Python · runnable

The three-piece pattern

  • Initialize — count = 0
  • Traverse + condition — for char in text: if char in vowels:
  • Update + return — count += 1 then return count

The in operator on strings

Python · runnable