curriculum/challenges/english/blocks/daily-coding-challenges-python/68e39ed6106dac2f0a98fd64.md
Given a string representing a variable name, convert it to "spooky case" using the following constraints:
_), and hyphens (-) with a tilde (~).For example, given hello_world, return HeLlO~wOrLd.
spookify("hello_world") should return "HeLlO~wOrLd".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(spookify("hello_world"), "HeLlO~wOrLd")`)
}})
spookify("Spooky_Case") should return "SpOoKy~CaSe".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(spookify("Spooky_Case"), "SpOoKy~CaSe")`)
}})
spookify("TRICK-or-TREAT") should return "TrIcK~oR~tReAt".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(spookify("TRICK-or-TREAT"), "TrIcK~oR~tReAt")`)
}})
spookify("c_a-n_d-y_-b-o_w_l") should return "C~a~N~d~Y~~b~O~w~L".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(spookify("c_a-n_d-y_-b-o_w_l"), "C~a~N~d~Y~~b~O~w~L")`)
}})
spookify("thE_hAUntEd-hOUsE-Is-fUll_Of_ghOsts") should return "ThE~hAuNtEd~HoUsE~iS~fUlL~oF~gHoStS".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(spookify("thE_hAUntEd-hOUsE-Is-fUll_Of_ghOsts"), "ThE~hAuNtEd~HoUsE~iS~fUlL~oF~gHoStS")`)
}})
def spookify(boo):
return boo
def spookify(boo):
replaced = boo.replace("_", "~").replace("-", "~")
result = []
capitalize = True
for char in replaced:
if char == "~":
result.append(char)
else:
result.append(char.upper() if capitalize else char.lower())
capitalize = not capitalize
return "".join(result)