0

Python code coach camel to snake last test question

Wrote a code i think is right and its going fine just except the last test. Tried to find out why but i have no idea… can any1 tell me whats wrong https://sololearn.com/coach/82/?ref=app

29th Jan 2023, 3:04 AM
AI 0523
6 Respuestas
+ 3
Your link is to the code coach itself. We cannot see what your code is. Can you copy the task here? And then, copy your code, open a new code in the code playground, paste your code there, save it and attach it here.
29th Jan 2023, 3:10 AM
Ausgrindtube
Ausgrindtube - avatar
+ 3
AI, Nearly right 👍 your first if statement doesn’t change a[0], just add the assignment: a[0] = a[0].lower() and your golden… a=input() a=list(a) if a[0].isupper(): a[0] = a[0].lower() for x in a: if x.isupper(): b=a.index(x) a[b]="_" + x.lower() a="".join(a) print(a) str.lower() returns a new str object (that’s why you needed to reassign) which I think your already knew but just missed (as you’ve done it in your second if statement already) 👍
29th Jan 2023, 10:18 AM
DavX
DavX - avatar
+ 3
No problem, good work and happy coding 👌👍
29th Jan 2023, 12:59 PM
DavX
DavX - avatar
+ 2
omg tysm for the solution <33 Actually i had no idea i have to reassign while using str.lower() I reassigned b=a.index(x) in the 2nd time bc before i was trying arr.insert() method(which didnt work) and when i thought of using the current way i just decided to use it And ty for the compliment it encouraged me alot !!
29th Jan 2023, 12:56 PM
AI 0523
29th Jan 2023, 5:12 AM
AI 0523
0
DavX thank you for pasted the code, I managed to pass the tests by using it, however I have two doubts: 1) I think it's just a coincidence if that code works because using the index function of the string should always return only the first occurrence of the character, if there were two equal uppercase characters in the input, the same code broke. 2) however my code fails the 5th test while the one you shared doesn't. I paste my code in case someone can tell me where there is an error: snake = input() camel = "" for c in snake: if c.isupper(): camel += '_' camel += c print(camel.lower())
30th Jul 2023, 5:25 PM
Giordano Balanzo
Giordano Balanzo - avatar