Raj Medhekar wrote:
So I figured out the solution to the missing letter and I will post my
code here. But I still need help figuring out the other stuff (please
see my original message included in this email)! Thanks for putting up
with me. Python is slowly but surely coming to me! I am psyched since
this is the first programming language that I am learning! Thanks all
for the assistance!
-Raj
New 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[::-1]
break
raw_input("\n\nPress the enter key to exit")
My Original message:
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@python.org
http://mail.python.org/mailman/listinfo/tutor
Hello,
The following works also.
msg = raw_input("\nPlease enter a message to print backwards: ")
x = range(0,len(msg))
x.reverse()
for i in x: print msg[i],
--ayyaz
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor