dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.9 KiB
1.9 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 691b559495c5cb5a37b9b488 | Challenge 128: Consonant Count | 29 | challenge-128 |
--description--
Given a string and a target number, determine whether the string contains exactly the target number of consonants.
- Consonants are all alphabetic characters except
"a","e","i","o", and"u"in any case. - Ignore digits, punctuation, spaces, and other non-letter characters when counting.
--hints--
has_consonant_count("helloworld", 7) should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(has_consonant_count("helloworld", 7), True)`)
}})
has_consonant_count("eieio", 5) should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(has_consonant_count("eieio", 5), False)`)
}})
has_consonant_count("freeCodeCamp Rocks!", 11) should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(has_consonant_count("freeCodeCamp Rocks!", 11), True)`)
}})
has_consonant_count("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 24) should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(has_consonant_count("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 24), False)`)
}})
has_consonant_count("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 23) should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(has_consonant_count("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 23), True)`)
}})
--seed--
--seed-contents--
def has_consonant_count(text, target):
return text
--solutions--
def has_consonant_count(text, target):
vowels = {"a", "e", "i", "o", "u"}
count = 0
for ch in text.lower():
if ch.isalpha() and ch not in vowels:
count += 1
return count == target