0
What am i missing in this challange?
I have simple challange which is converting camel case to snake case. All test cases are right expect the last one but sololearn only display two test cases at maximum so i couldnt figure out what am i missing. In this code def snake_case(inp): res = '' for i in range(0,len(inp)): res += '_'+inp[i].lower() if inp[i].isupper() else inp[i].lower() return res inp = input() print(snake_case(inp))
2 Antworten
+ 1
According to rule of snake_case if name has multiple words then they are separated by underscores.
I mistake for
>>>Input: "Sample"
>>>Output: "_sample"
Which was wrong
So I corrected it and solution works now
def snake_case(inp):
res = inp[0].lower()
for i in range(1,len(inp)):
res += '_'+inp[i].lower() if inp[i].isupper() else inp[i].lower()
return res
inp = input()
print(snake_case(inp))
+ 1
The other thing you can (and should) do is temporarily change inp = input() to inp= some specific (difficult/tricky) test case so you can at least see what your code is doing (in the "your output" of test case 1). Make sure your code is behaving the way you want and expect it to.