22 lines
732 B
Python
22 lines
732 B
Python
def to_camel_case(name):
|
|
name = name[0].upper() + name[1:]
|
|
while True:
|
|
try:
|
|
index = name.index("_")
|
|
name = name[0:index] + name[index+1].upper() + name[index+2:]
|
|
except ValueError:
|
|
break
|
|
return name
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print("Example:")
|
|
print(to_camel_case('name'))
|
|
|
|
# These "asserts" using only for self-checking and not necessary for auto-testing
|
|
assert to_camel_case("my_function_name") == "MyFunctionName"
|
|
assert to_camel_case("i_phone") == "IPhone"
|
|
assert to_camel_case("this_function_is_empty") == "ThisFunctionIsEmpty"
|
|
assert to_camel_case("name") == "Name"
|
|
print("Coding complete? Click 'Check' to earn cool rewards!")
|