curriculum/challenges/english/blocks/daily-coding-challenges-python/694596b0585c11170ac7c7fb.md
Given a string representing a variable name, convert it to consonant case using the following rules:
a, e, i, o, u in any case) should be converted to lowercase.-) should be converted to underscores (_).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_~_")`)
}})
def to_consonant_case(s):
return s
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