7. Reverse: Removing spaces in output


I could use some help on "Practice Makes Perfect" exercise 7: reverse.

I am getting the error message "Oops, try again. Your function fails on reverse("Python!"). It returns "None" when it should return "!nohtyP".", although it looks like the code actually does do something: it returns the following:

! g f e d c b a

I think the only problem is that there are spaces inbetween the characters? Is there any way to fix this?

def reverse(text):
    for n in range(1,len(text)):
        print text[len(text) - n],
    print text[0]


Obviously this is what it returns for the string "abcdefg!", I did not include the lines calling the function.


You are printing when you should be returning. Python prints a space when comma is used.


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