[Tutor] Help Needed
Raj Medhekar
cosmicsand27 at yahoo.com
Tue Jun 16 23:25:00 CEST 2009
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")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090616/905a78ea/attachment-0001.htm>
More information about the Tutor
mailing list