Reverse


#1

Hey!
so I wrote this code for the reverse practice:

reverse_list = []
def reverse(text):
x = -1
n = len(text)
for letters in text:
if x >= -n:
reverse_list.append(text[x])
x = x-1
new_word = ''.join(reverse_list)
return new_word

but there is the following error:
Oops, try again. Your function fails on reverse("Python!"). It returns "cba!nohtyP" when it should return "!nohtyP".

And I don't understand where the "abc" comes from! When I run the code on my Idle it works just fine.
Thanks!


#2

the exercise calls the function multiply times for validition, but only the function, not whole script. So place reverse_list inside the function


#3

Thanks a lot!!
Although I still don't get why the "cba" appeared there, unless it is a mistake


#4

its one of the test cases of exercise/validition


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.