+ 2

Camel to Snake, Code Coach [Solved]

str = input() for i in range(len(str)): if i != 0: # to avoid first letter if it's capital e.g. CodeCoach if str[i].isupper(): str = str.replace(str[i], '_'+str[i].lower()) print(str.lower()) I have solved Camel to Snake code coach problem, and it passed every Test Cases except Test Case #5. Does anyone knows what in Test Case #5?

10th Mar 2024, 3:05 PM
Armash Ansari
7 odpowiedzi
+ 3
Rain Wong Hei Ming Thank you very much for all your responses, it means a lot. I've finally solved this problem using python enumerate() built-in function. Here, I've attached my solution, please review it and let me know if I can make it better. https://sololearn.com/compiler-playground/cirv9Uqr8WXF/?ref=app
10th Mar 2024, 8:01 PM
Armash Ansari
+ 2
What would happen if the string is "ItIsFun"?
10th Mar 2024, 3:18 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
Are you sure? Did you tried it with your code?
10th Mar 2024, 3:58 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
No bad. But please don't use python keywords as variable name. If you add another piece of code below your solution, it might produce an error. example: <code added below to your original code> b = 10 print(str(b)) result: Traceback (most recent call last): File "./Playground/file0.py", line 18, in <module> print(str(b)) TypeError: 'str' object is not callable
11th Mar 2024, 1:38 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Armash Ansari , Test Case #5's input is actually in PascalCase or UpperCamelCase, not camelCase.
10th Mar 2024, 7:25 PM
Rain
Rain - avatar
+ 1
Armash Ansari , It looks well organized.
10th Mar 2024, 8:08 PM
Rain
Rain - avatar
+ 1
Wong Hei Ming, Good point, I've replaced variable name 'str' to 'camel'. I think that'd be more related and won't create problems if I add another piece of code below it.
11th Mar 2024, 7:13 AM
Armash Ansari