name = raw_input("Enter a name")
for i in range(-len(name),0):
a = name[i]
print a
Asked
Active
Viewed 70 times
-3
-
Can you tell us what you see wrong with it and what input you are providing and how it is breaking? – idjaw Feb 11 '18 at 01:41
-
Welcome to SO. Unfortunately this isn't a discussion forum or tutorial service. Please take the time to read [ask] and the other links on that page. You should invest some time working your way through [the Tutorial](https://docs.python.org/3/tutorial/index.html), practicing the examples. It will give you an introduction to the tools Python has to offer and you may even start to get ideas for solving your problem. – wwii Feb 11 '18 at 01:44
-
You should switch to Python 3.6+ while you are still learning. https://pythonclock.org/ – wwii Feb 11 '18 at 01:45
-
Please take a look at [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and then edit your question accordingly. – Brien Foss Feb 11 '18 at 01:52
4 Answers
1
One way to do it in Python2 is:
name = raw_input("Enter a name")
for i in range(0, len(name)):
a = name[len(name)-1-i]
print(a)

dmitryro
- 3,463
- 2
- 20
- 28
0
You probably want to go backwards like:
Code:
name = "Enter a name"
for i in range(len(name), 0, -1):
a = name[i-1]
print(a)
But even better is:
print(''.join(reversed(name)))
Results:
e
m
a
n
a
r
e
t
n
E
eman a retnE

Stephen Rauch
- 47,830
- 31
- 106
- 135
0
name = raw_input("Enter a name")
for i in range(len(name)-1 ,0,-1):
a = name[i]
print a

Mheni
- 228
- 4
- 15
0
In the loop if you just assign to a, it will only have the first character of the original after the loop. If you need the full string after the loop, you need to keep appending to a. Also your range values are incorrect,Try the following,
name = raw_input("Enter a name")
a=''
for i in range(len(name)-1,-1, -1):
a += name[i]
print(a)
If you want the shorter approach, try the following,
name = raw_input("Enter a name")
a = name[::-1]
print(a)

Skyler
- 656
- 5
- 14