Lesson guide
What this Python exercise practices
Reverse a String with a Loop is a beginner practice lesson that focuses on strings, formatting, traversal. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- String values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Related public exercises
Summary
Learn to reverse the characters in a string using iteration.
Problem statement
Given a string s, return a new string that contains the characters of s in reverse order. Use iteration (for loop or while loop) to traverse the string and build the reversed result. Do not use built-in slicing reversal (e.g., s[::-1]) in the starter exercise; learners should practice loop-based construction.
Task
Write a function that returns the input string with characters in reverse order.
Examples
Simple example
Input
reverse_string("hello")
Output
olleh
Explanation
The input 'hello' reversed is 'olleh'.
Input format
A single function call reverse_string(s) where s is a string.
Output format
Return a string containing the characters of s in reverse order.
Constraints
0 <= len(s) <= 1000. The string may include spaces, punctuation, and Unicode characters.
Samples
Sample input 0
reverse_string("abcde")
Sample output 0
edcba
Explanation 0
Each character is placed in reverse order.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.