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

  • Initializecount = 0
  • Traverse + conditionfor char in text: if char in vowels:
  • Update + returncount += 1 then return count

The in operator on strings

Python · runnable