0
CamelCase to snake_case
a = input() #camelCaseDoing to camel_case_doing ac = a[0] for x in a[1:]: if (x.isalpha() and x.upper() == x): x = '_' + x.lower() ac += x print(ac)
5 Respostas
+ 1
Hi Sanjay Sahu there is a hint in the task. If the first letter is upper it shouldn't take an underscore. Your code actually is missing the case if the first letter is capital.
+ 1
Oh yeah I didn't notice that, great you found what to do yourself 👍
0
This code passes first 4 tests, but not the 5th one..!!
0
Julian Zimpel
Thanks for your response..!
I had actually taken the first letter as is through following variable declaration:
ac = a[0]
I was converting uppercase letter into _+lowercase from 2nd letter onwards..
I've now rectified my code by changing the above line of code into:
ac = a[0].lower ()
Finally, the code has been able to pass all tests..!!
0
Hi Julian Zimpel , your remarks actually gave me the much needed insight for rectifying the code.