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
6 Réponses
+ 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.
+ 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) 👍
+ 3
No problem, good work and happy coding 👌👍
+ 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 !!
0
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())