Reverse


#1


HI Everyone,

I am stuck at this exercise and not sure what I am doing wrong. Any help?

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

Error:

Oops, try again. Your function fails on reverse("Python!"). It returns "!" when it should return "!nohtyP".


def reverse(text):
    total = []
    for i in range(len(text)-1,-1,-1):
        total.append(text[i])
        return "".join(total)


#2

Indentation need to be fixed here.
as at first iteration it appends the first letter in reverse and it sees return statement and when function sees return statement it executes it and halts the process.


#3

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