Reverse - stuck


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096


It should return !nohtyP but I get this weird error message: Your function fails on reverse("Python!"). It returns "cba!nohtyP" when it should return "!nohtyP". While testing the function I created a str variable called "test" and assigned abc and removed afterwards.

I checked whether the list is empty before the function is called so when printed it returns as [] so I believe it is empty


result = []
def reverse(text):
    for n in range(1,len(text)+1):
        result.append(text[len(text)-n])
    return ''.join(result)


#2

the exercise calls the function multiply times for different string to see it works correctly.

so place result = [] inside the function


#3

so in my case the the loop is not able to append to results since it is a global list rather than a locak one?


#4

no, the exercise calls the function multiply times to validate it works correctly.

not the whole script, so the list will maintain data from earlier function calls


#5

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