Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. exercise = """Exercise 6
  2. Ask the user for a string and print out whether this string is a palindrome or not.
  3. (A palindrome is a string that reads the same forwards and backwards.)"""
  4.  
  5. # this was the first thing I've done, without recalling how easy it is to reverse strings in python
  6. def palindromeOrNot(a):
  7. new = list(a)
  8. for i in range(len(new)):
  9. if new[i] == new[len(new)-1]:
  10. return(True)
  11. else:
  12. return(False)
  13.  
  14. print(palindromeOrNot(input("give me a word plz\n")))
  15.  
  16. # this is after considering reversing a string, which clearly makes it concise.
  17. def again(a):
  18. return(True if a[::-1] == a else False)
  19.  
  20. print(again(input("give me sumthin\n")))
  21.  
  22. # PS: one might omit ()s in return and print if the python version at hand is 2.7.x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement