Given a string in camel case, write a python program to convert the given string from camel case to snake case.
how to slove and what is wrong in my code
w = input()
first_char = w[0]
first_char = first_char.lower()
#print(first_char)
remining_chars = w[1:]
capl = 0
for char in remining_chars:
if char == char.upper():
break
capl -= 1
lower = w[:capl].lower()
new = w[lower:]
print(new)
w = input('Enter string in camel case: ')
list1 = []
for i in w:
if i.isupper() == True or w.index(i)==0:
list1.append(i)
for i in w:
if i in list1[1:]:
print('_'+i.lower(),end='')
elif i == list1[0]:
print(i.lower(),end='')
else:
print(i,end='')
Enter string in camel case: headOfDepartment
head_of_department
#There is an error in the second to the last line of your code as you used the
#string for slice indices
Comments
Leave a comment