Reverse word function


#1



I think this code is correct but...

def reverse(x):
N = str(x)
s = ""
for i in range(1,len(N)+1):
s += N[len(N)-i]
print s


In the console, it works, if I do reverse("Python!"), it gives me the right result. However, I didn't seem to pass the test because in the prompt box it says that the above returns None -- I'm not sure why that is the case, as it returned !nohytP


Replace this line with your code.


#2

no, your function prints the reversed string. It doesn't return it. None is returned by default by a function


#3

I see. I should write return s rather than print s


#4

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