0

Reverse Word function in Python wont return

Trying to create a function that calls on itself and another function to reverse a word and print them on separate lines. It creates the new variable has the letters and is formatted correctly, but when you try to return anything it doesn’t work. Even if you put a number or string it won’t return. To test different words change txt to string. Thanks for your help! https://code.sololearn.com/c5uQwMmgY5iY/?ref=app

24th Jul 2021, 5:00 AM
VenomousHamsterX
2 odpowiedzi
0
Your function returns None, because you ain’t returning anything. Look again your “spell”function returns a value then and only then if txt and test lengths are equal, but when they aren’t, else block executes and calls “spell” again, which calls “spell” again until everything is formatted as y say. However, after this call is made, your primary “spell” instance dies without returning anything, that’s when None comes into play. You may wonder where then return on line 10 goes. It goes straight to the place, where it was called (line 14). And because you don’t handle it, it just disappears. In order to save this value you just have to add a return statement before “spell” call in line 14. And it must work.
30th Jul 2021, 6:20 PM
Artem
0
Even though your code works, I would do something like this https://code.sololearn.com/cSBNY6BpVxPq/?ref=app This thing is called “slice” I strongly recommend checking it out
30th Jul 2021, 6:30 PM
Artem