GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python Exercise: Reverse a word - w3resource

Python Exercise: Reverse a word

Last update on April 17 2025 12:58:32 (UTC/GMT +8 hours)


5. Reverse a Word

Write a Python program that accepts a word from the user and reverses it.

Pictorial Presentation:

Python Exercise: Reverse a word

Sample Solution:

Python Code:

# Prompt the user to input a word
word = input("Input a word to reverse: ")

# Iterate through the characters of the word in reverse order
for char in range(len(word) - 1, -1, -1):
    # Print each character from the word in reverse order without a new line (end="")
    print(word[char], end="")

# Print a new line to separate the reversed word from the next output
print("\n")

Sample Output:

Input a word to reverse: ecruoser3w  
w3resource

Flowchart:

Flowchart: Python program that accept a word from the user and reverse it

For more Practice: Solve these Related Problems:

  • Write a Python program to reverse a word entered by the user using slicing.
  • Write a Python program to reverse each word in a sentence while maintaining the word order.
  • Write a Python program to recursively reverse a given string without using slicing.
  • Write a Python program to reverse a word using a stack data structure to simulate character popping.

Go to:

  • Python Conditional Statements and loops Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to construct the following pattern, using a nested for loop.
Next: Write a Python program to count the number of even and odd numbers from a series of numbers.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.