Advertisement
Guest User

reverse

a guest
Dec 3rd, 2019
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #Function to print a string backwards
  2. def reverse_string(str):
  3. #slice the string
  4. return str[::-1]
  5.  
  6. #ask the user to enter a string
  7. str = input("Enter a word or sentence to be reversed; ")
  8. #display the original string and call the reverse string function and
  9. #print the output of the fuction
  10. print("The original word or sentence was " + str + " and reversed is; " + reverse_string(str))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement