Backwards Message


/ Published in: Python
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.