range(N, -1) Follow
I am learning using Pycharm and Python Programming 3rd edition for absolute beginners.
Am at Chapter 4, (not far along , I know) and I,m stuck.
In a challenge you have to write a program that get a message from the user and then print it out backwards.
I have managed to write a program that seems to work but, the first letter of the message is always printed first and not last as expected.
If I ad a space at the beginning of the message then it prints as expected, of course you don't see the beginning space.
I am missing something or doing something wrong. I can't move on until I've sorted it.
Hope somebody can help me. I have attached the program.
Thanks
Am at Chapter 4, (not far along , I know) and I,m stuck.
In a challenge you have to write a program that get a message from the user and then print it out backwards.
I have managed to write a program that seems to work but, the first letter of the message is always printed first and not last as expected.
If I ad a space at the beginning of the message then it prints as expected, of course you don't see the beginning space.
I am missing something or doing something wrong. I can't move on until I've sorted it.
Hope somebody can help me. I have attached the program.
Thanks
Please sign in to leave a comment.
message = input("Your message please
? ",)
print ("\nMessage",len(message))
print()
mes = int(len(message))
for i in range(mes):
print (message [-i], end=" ")
print("\n\n\nIf I add a a space at the begining of the message this is the result -")
print ("Not sure what I'm missing")
print("\n")
? "))
mes = int(len(message))
print("\n\n")
print (message, mes)
for i in range(mes):
print (message [-i], end= " ")
print ("\n\n")
for i in range(10, 0, -1):
print (i ,end=" ")
input ("\nPress the Enter Key to exit.")
but like Preston said relating to range, try this:
Also, you don't have to turn len(message) into an int, as len() returns an int.