Define a function calledwhich takes a string and
returns the number of consonants in the string (uppercase or
lowercase). For this problem, you may consider only letters in the
English language alphabet only. Also, for this problem "Y" is
considered a consonant (...not a vowel!). So for example
count_engcons("Aeiou!"). You must use a
you are not allowed to use themethod on this problem.
vowels = ("aeiou")
count = 0
for count_engcons in text:
if not count_engcons in vowels:
count += 1
You were checking if a character wasn't a vowel, so it would give bad results for characters such as
?, you were also trying to access the string with different variable names (
text), which makes no sense.
def count_engcons(text): consonants = "bcdfghijklmnpqrstvwxyz" count = 0 for c in text.lower(): if c in consonants: count += 1 return count