[Tutor] Help Needed
bermanrl at cfl.rr.com
Tue Jun 16 23:33:16 CEST 2009
You are putting far too much work into the solution. Look up slicing on
the python web page. Then, as an example,
In : s1 = 'hello world'
In : s1[::-1]
Out: 'dlrow olleh'
Hope this helps,
On Tue, 2009-06-16 at 14:25 -0700, Raj Medhekar wrote:
> I had previously emailed y'all regarding inverting a message input by
> the user of the program backwards. After much contemplation on your
> earlier replies I came up with the code I have included in this email.
> The problem I am having with this code is that the the first character
> of the message that is reversed does not come up. Is there a solution
> to this? For my message that I input I used "take this" to test it,
> use the same message when the program prompts you to enter the message
> and run it, you'll see what I mean. Also is there a way to say reverse
> the string in a way so the reversed string would result to "this take"
> if you use my example? And is there a way to stop the loop without the
> use of break? Thanks for the help!
> My Code:
> # Backward message
> # program gets message from user then prints it out backwards
> message = raw_input("Enter your message: ")
> print message
> high = len(message)
> low = -len(message)
> while begin != "":
> begin = int(high)
> if begin:
> end = int(low)
> print "Your message backwards is",
> print message[begin:end:-1]
> raw_input("\n\nPress the enter key to exit")
> Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor