/ Published in: Python
Two ways of printing a message backwards using either string slicing, or list() function.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#------------------------------------------------------------------------------- # Name: Backwards message # Purpose: Prints message entered by user backwards using string # slicing or list() function # # Author: John Santiago Jr. # # Created: 03/04/2012 #------------------------------------------------------------------------------- def message_lst(): message = input('Enter Message: ') new_message = list(message) new_message.reverse() print('Your message backwards is:') print(''.join(new_message)) def message_str(): message = input('Enter Message: ') new_message = '' while message: new_message += message[-1] message = message[:-1] print('Your message backwards is:') print(new_message)