Reverse working in IDLE and it works but on Code Academy?


#1

On IDLE I run this function and I get the correct outcome but code acadamy keeps telling me it is returning 'None'....

def reverse(text):

rev=[]
for item in text:
    rev.insert(0,item)
output="".join(rev)
print (output)

#2

What is the return value of your function?

my_reversed_name = reverse('ionatan')
print 'my name looks like this after reversing it:', my_reversed_name

#3

Thanks you've helped me inadvertly solve it. Code Academy wanted to to return the answer not print it.


#4

No, that was very intentional.
It told you your return value was wrong, so check the return value. You assumed that you did what it said you did not. Assumptions are useful, but if you treat them like facts then this is what happens.


#5

Ah I see, well thank you either way. Can I ask what the difference would be to put the print function in instead of the return?


#6

Imagine if the + operator printed the result on the screen instead of returning a value to use. The result would be on screen, but your code wouldn't be able to use it.

5+5

Great, now the user knows about the value 10. But I want to subtract 2 from the result? I guess I'm out of luck.