0

Please help me, I need my code free of Recursion error

def reversed(x): string=reversed(x) return string a='asdf' print(reversed(a))

14th Jun 2021, 10:59 AM
Kevin Ngigi
Kevin Ngigi - avatar
6 ответов
+ 5
Kevin Ngigi , to get help, you need to share some more information with us. ▪︎please give us a brief description of the task that has to be done ▪︎also give a sample of input and output dara that is expected i would also recommend you to work through the python tutorial, there is a sample where recursion is demonstrated. thanks!
14th Jun 2021, 11:08 AM
Lothar
Lothar - avatar
+ 4
def reversed(x): string= x[::-1] return string a='asdf' print(reversed(a))
14th Jun 2021, 11:06 AM
TOLUENE
TOLUENE - avatar
+ 3
dont call your own function inside of itself. you made a function called reversed and the first thing you do is call the same function again. it will keep doing that forever
14th Jun 2021, 11:04 AM
Slick
Slick - avatar
+ 2
What are you trying to achieve by calling function again and again ?
14th Jun 2021, 11:05 AM
Abhay
Abhay - avatar
+ 2
def reversed1(x): text = ''.join(reversed(x)) return text a='asdf' print(reversed1(a))
14th Jun 2021, 11:07 AM
SammE
SammE - avatar
0
you doesn't need recursion to achieve that... however, if you absolutly want to use recursion: def reversed(st): if len(st)<2: return st return st[-1]+reversed(st[:-1]) print(reversed(input())) but it's shorter and more efficient to do: print(input()[::-1])
14th Jun 2021, 3:33 PM
visph
visph - avatar