+ 2

How to print a string in reverse using recursion on python

5th Apr 2021, 4:15 PM
sid
sid - avatar
5 Antworten
+ 5
Jan Markus ,Operand, iTech ,Per Bratthammar Thanks guyz .really appreciated. #STAYSafe !!
6th Apr 2021, 6:15 AM
sid
sid - avatar
+ 2
iTech: There is no really meaning with all this code in your case. This would be enough: print(input()[::-1]) And it is no recursion either, as the question was about. To be recursion you have at least, from inside of the function, make a call back to an earlier instance (function value) of the function itself. /Regards Per B
6th Apr 2021, 3:18 AM
Per Bratthammar
Per Bratthammar - avatar
5th Apr 2021, 6:07 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Here's my way of doing it: def rec(a): if not a: return "" return a[-1] + rec(a[:-1]) # Hope this helps
6th Apr 2021, 6:55 AM
Calvin Thomas
Calvin Thomas - avatar