This Python program reads an integer from the user and checks whether it is palindromic.
A number is considered palindromic if it remains the same when its digits are reversed.
number = input("Please enter a number: ")
if number == number[::-1]:
print("The number is palindromic.")
else:
print("The number is not palindromic.")
Please enter a number: 12321
The number is palindromic.
Please enter a number: 4567
The number is not palindromic.
Here’s how the program works:
- The number is read as a string so its digits can be reversed easily
- The slicing operation [::-1] is used to reverse the string
- If the original number matches its reversed version, it is palindromic
- The result is displayed using the print() function