This is a Python Program to reverse a string without using recursion.
Problem Description
The program takes a string and reverses the string without using recursion.
Problem Solution
1. Take a string from the user.
2. Use string slicing to reverse the string.
3. Print the reversed string.
4. Exit.
Program/Source Code
Here is source code of the Python Program to reverse a string without using recursion. The program output is also shown below.
a=str(input("Enter a string: ")) print("Reverse of the string is: ") print(a[::-1])
Program Explanation
1. User must enter a string.
2. By giving the increment value as -1, string slicing is used to reverse the list.
3. The reversed string is printed.
advertisement
advertisement
Runtime Test Cases
Case 1: Enter a string: hello Reverse of the string is: olleh Case 2: Enter a string: test Reverse of the string is: tset
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
Related Posts:
- Practice Programming MCQs
- Check Python Books
- Apply for Python Internship
- Check Information Technology Books
- Apply for Programming Internship