[Tutor] Help Needed

Robert Berman 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 [1]: s1 = 'hello world'

In [2]: s1[::-1]
Out[2]: 'dlrow olleh'

Hope this helps,

Robert

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!
> 
> Peace,
> Raj
> 
> 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)
> 
> begin=None
> while begin != "":
>     begin = int(high)
> 
>     if begin:
>         end = int(low)
> 
>         print "Your message backwards is",
>         print message[begin:end:-1]
>         break
> 
> 
> raw_input("\n\nPress the enter key to exit")
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090616/c27653d9/attachment.htm>


More information about the Tutor mailing list