I wrote a short script to tell me if a phrase taken in by a user is a palindrome or not, and I'm wondering how I can shorten my current code.
Here is the current code:
def palindrome():
string = input()
stringremove = string.replace(" ", "")
if stringremove[0] == stringremove[-1]:
if stringremove[1] == stringremove[-2]:
if stringremove[2] == stringremove[-3]:
if stringremove[3] == stringremove[-4]:
print("It's a palindrome!")
else:
print("It's not a palindrome!")
else:
print("It's not a palindrome!")
else:
print("It's not a palindrome!")
else:
print("It's not a palindrome!")
palindrome()
Obviously I could keep going for longer and longer phrases / words, but I'm thinking there is an easy way to get around this with much shorter code.