You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This is a Python Program to reverse a string using Recursion.
Problem Description:
The program takes a String and reverses the string using Recursion.
Problem Solution:
Take a string from the user.
Pass the string as an argument to a recursive function to reverse the string.
In the function, put the base condition that if the length of the string is equal to 0, the string is returned.
Otherwise recursively call the reverse function to slice the part of the string except the first character and concatenate the first character to the end of the sliced string.
Print the reversed string.
Exit.
Program Explanation:
User must enter a String.
The string is passed as an argument to a recursive function to reverse the string.
In the function, the base condition is that if the length of the string is equal to 0, the string is returned.
If not equal to 0, the reverse function is recursively called to slice the part of the string except the first character and concatenate the first character to the end of the sliced string.
The reversed string is printed.
Runtime Test Cases:
Case 1:Enter the string to be reversed: hello worlddlrow olleh
Case 2:Enter the string to be reversed: firsttsrif
About
Implementation of Reverse String using Recursion in Python