0

How to fix this

I want to create a program which reverses a string using recursion. Why the error is happening and how to fix it? https://code.sololearn.com/cX8UuyP6a5u8/?ref=app

26th May 2020, 9:27 AM
Anonymous Person
Anonymous Person - avatar
3 Answers
+ 4
Anonymous Person On line number 6 you have passed number as parameter which doesn't has len() rev(n-1) //wrong Change rev(n - 1) to rev(string[:n]) https://code.sololearn.com/ccf9QK7HSJwb/?ref=app
26th May 2020, 9:31 AM
A͢J
A͢J - avatar
0
Here is the simple way, def rev(string): if len(string) == 0: return "" return (string[-1] + rev(string[:-1])) print(rev("news"))
26th May 2020, 10:24 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar