# String reverse using recursion
def fnReverse(S):
if(len(S)==0):
return S
else:
return fnReverse(S[1:])+S[0]
S = input("Enter string to reverse: ")
print("Reversed string :",fnReverse(S))
"""
Sample output
>python StringReverseRecursion.py
Enter string to reverse: Hello Python
Reversed string : nohtyP olleH
"""
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu