Posted By

jdsantiagojr on 04/02/12


Tagged

python 3


Versions (?)

Backwards Message


 / Published in: Python
 

Two ways of printing a message backwards using either string slicing, or list() function.

  1. #-------------------------------------------------------------------------------
  2. # Name: Backwards message
  3. # Purpose: Prints message entered by user backwards using string
  4. # slicing or list() function
  5. #
  6. # Author: John Santiago Jr.
  7. #
  8. # Created: 03/04/2012
  9. #-------------------------------------------------------------------------------
  10.  
  11. def message_lst():
  12. message = input('Enter Message: ')
  13. new_message = list(message)
  14. new_message.reverse()
  15.  
  16. print('Your message backwards is:')
  17. print(''.join(new_message))
  18.  
  19. def message_str():
  20. message = input('Enter Message: ')
  21. new_message = ''
  22.  
  23. while message:
  24. new_message += message[-1]
  25. message = message[:-1]
  26.  
  27. print('Your message backwards is:')
  28. print(new_message)

Report this snippet  

You need to login to post a comment.