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.8 KiB
1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 694596b0585c11170ac7c7fb | Challenge 163: Consonant Case | 29 | challenge-163 |
--description--
Given a string representing a variable name, convert it to consonant case using the following rules:
- All consonants should be converted to uppercase.
- All vowels (
a,e,i,o,uin any case) should be converted to lowercase. - All hyphens (
-) should be converted to underscores (_).
--hints--
to_consonant_case("helloworld") should return "HeLLoWoRLD".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("helloworld"), "HeLLoWoRLD")`)
}})
to_consonant_case("HELLOWORLD") should return "HeLLoWoRLD".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("HELLOWORLD"), "HeLLoWoRLD")`)
}})
to_consonant_case("_hElLO-WOrlD-") should return "_HeLLo_WoRLD_".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("_hElLO-WOrlD-"), "_HeLLo_WoRLD_")`)
}})
to_consonant_case("_~-generic_~-variable_~-name_~-here-~_") should return "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("_~-generic_~-variable_~-name_~-here-~_"), "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_")`)
}})
--seed--
--seed-contents--
def to_consonant_case(s):
return s
--solutions--
def to_consonant_case(s):
vowels = "aeiouAEIOU"
result = ""
for char in s:
if char == "-":
result += "_"
elif char.isalpha():
if char in vowels:
result += char.lower()
else:
result += char.upper()
else:
result += char
return result