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
2 RĂ©ponses
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.
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