7. Reverse: Removing spaces in output


#1



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
None


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]


#2

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


#3

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


#4

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