Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exercise = """Exercise 6
- Ask the user for a string and print out whether this string is a palindrome or not.
- (A palindrome is a string that reads the same forwards and backwards.)"""
- # this was the first thing I've done, without recalling how easy it is to reverse strings in python
- def palindromeOrNot(a):
- new = list(a)
- for i in range(len(new)):
- if new[i] == new[len(new)-1]:
- return(True)
- else:
- return(False)
- print(palindromeOrNot(input("give me a word plz\n")))
- # this is after considering reversing a string, which clearly makes it concise.
- def again(a):
- return(True if a[::-1] == a else False)
- print(again(input("give me sumthin\n")))
- # 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