Requirements
- Create the function
count_vowels_consonants(s) to process one string.
- Before counting anything, verify that every character in
s is a letter or a digit.
- When the input passes that check, count its vowel characters and consonant letters separately.
- Although digits satisfy the alphanumeric requirement, do not include them in either count.
- Return the two counts using the representation required by the assessment.
def count_vowels_consonants(s):
pass
Examples
The outputs below show the counts as [vowels, consonants] for valid inputs.
- output
[2, 3]
The vowels are O and i, the consonants are r, b, and t, and 7 is ignored for both totals.
- output
[0, 0]
Every character is a digit, so the string contains neither vowels nor consonant letters.
- output
[2, 5]
u and e are vowels, while B, l, S, k, and y are counted as consonants under the usual letter classification.
Notes
- Treat
a, e, i, o, and u as vowels without regard to letter case.
- Use an alphanumeric check that rejects underscores, spaces, punctuation, and other symbols.
- Establish the invalid-input result before implementing the function: the assessment may require
false, [-1, -1], or another error indicator, and the title does not determine that choice.
Constraints
- The input is one string.
- Letters may appear in either uppercase or lowercase.
- Valid strings contain only letters and digits.
- Digits contribute to validation but never to either count.
Preparation
- Scan the string without distinguishing uppercase from lowercase.
- For each character, handle the digit, vowel, and consonant cases separately.
- Include tests for uppercase letters, an input made entirely of digits, a mixed letter-and-digit value, and a string containing punctuation.