On 2/6/2012 2:05 PM, myles broomes wrote:
Im trying to code a program where the user enters a message and it is
returned backwards. Here is my code so far:
------------------------------------------------------------------------
message = input("Enter your message: ")
backw = ""
counter = len(message)
while message != 0:
backw += message[counter-1]
counter -= 1
print(backw)
input("\nPress enter to exit...")
------------------------------------------------------------------------
I run the program, type in my message but get back the error code:
'IndexError: String out of range'
I was thinking that maybe the problem is that each time a letter is
taken from 'message' and added to 'backw', the length of message
becomes a letter shorter
1 - message never changes. Why did you think letters were "taken" from
it? They are copied.
2 - comparing an integer to a string is always False
--
Bob Gailer
919-636-4239
Chapel Hill NC
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor