This program allows users to enter a sentence and choose between two methods to reverse the string: using a for loop or using string slicing. It's a simple project focused on working with strings, loops, and basic functions in Python.
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
The program starts by prompting the user to input a sentence and choose a method for reversing it. It then:
- Reverses the string using a for loop, iterating through each character and building the reversed string.
- Alternatively, reverses the string using Python's slicing method for a more concise approach.
- Displays the reversed string based on the selected method.
If an invalid method is chosen, the program will prompt the user to select a valid option.
- Python 3.x
- Clone this repository or download the
reverse_string.py
file. - Ensure you have Python installed on your computer. This code works with Python 3.x.
Run the program and follow the prompts:
- Enter the sentence you want to reverse.
- Choose the method for reversing the string:
- Type
for
to reverse using a for loop. - Type
slicing
to reverse using the slicing method.
- Type
- The program will display the reversed string based on your selected method.
This project is licensed under the MIT License - see the LICENSE file for details.