I know how to reverse the string, my only issue is how do I make the "!" reverse as well?

Replace this line with your code. 

def reverse(text):
    rev = ""
    l = len(text) - 1
    for x in range(len(text)-1, -1, -1):
        rev = rev + text[x-1]
    return rev


def reverse(text):
    rev = ''
    count = len(text)
    while count > 0:
        rev += text[count - 1]
        count -= 1
    return rev
    print rev

This is how I did it, it is a bit neater.

Called a function reverse with argument text.
Set rev equal to an empty string.
Set the variable count equal to the length of the functions argument text.
Executed a while loop: while count is greater than 0
rev is equal to itself plus text count -1
count is equal to itself minus 1
return rev
print rev


Thanks for the quick response!


def reverse(text):
if len(text)>1:
return reverse(text[1:])+text[0]

return text

Oops, try again. Your code looks a bit off–it threw a “maximum recursion depth exceeded” error. Check the Hint if you need help!


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