What am i missing in this challange? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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))

31st May 2023, 8:39 AM
Bishnu Chalise
Bishnu Chalise - avatar
2 Answers
+ 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))
31st May 2023, 1:57 PM
Bishnu Chalise
Bishnu Chalise - avatar
+ 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.
31st May 2023, 1:37 PM
Orin Cook
Orin Cook - avatar