Skip to content

A Python program that lets users reverse a string by choosing between two methods: a for loop or string slicing.

License

Notifications You must be signed in to change notification settings

iBensusan/Two-ways-of-reverse-a-String

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Two Algorithms to Reverse a String

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.

Project Level: Beginner

This project is designed for beginner learners who are still learning and practicing Python fundamentals.

How the Project Works

The program starts by prompting the user to input a sentence and choose a method for reversing it. It then:

  1. Reverses the string using a for loop, iterating through each character and building the reversed string.
  2. Alternatively, reverses the string using Python's slicing method for a more concise approach.
  3. 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.

Requirements

  • Python 3.x

Installation

  1. Clone this repository or download the reverse_string.py file.
  2. Ensure you have Python installed on your computer. This code works with Python 3.x.

Usage

Run the program and follow the prompts:

  1. Enter the sentence you want to reverse.
  2. Choose the method for reversing the string:
    • Type for to reverse using a for loop.
    • Type slicing to reverse using the slicing method.
  3. The program will display the reversed string based on your selected method.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Python program that lets users reverse a string by choosing between two methods: a for loop or string slicing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages