Reverse word function


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.


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


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


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