def is_palindrome(string):
# Remove any spaces and convert the string to lowercase
string = string.replace(" ", "").lower()
# Reverse the string
reversed_string = string[::-1]
# Check if the reversed string is equal to the original string
if string == reversed_string:
return True
else:
return False
# Get the input string from the user
input_string = input("Enter a string: ")
# Check if the string is a palindrome
if is_palindrome(input_string):
print("It is a palindrome.")
else:
print("It is not a palindrome.")
In this program, the is_palindrome function takes a string
as input and checks if it is a palindrome. It removes any spaces and converts
the string to lowercase. Then, it reverses the string using slicing. Finally,
it compares the reversed string with the original string to determine if they
are equal.
The program prompts the user to enter a string and then calls the is_palindrome
function to check if the string is a palindrome. It prints the appropriate
message based on the result.