190k views
5 votes
Write a program that checks whether an entered 4-digit number is
a palindrome or not.

User Discover
by
7.2k points

1 Answer

3 votes

Final answer:

To check whether a 4-digit number is a palindrome or not, you can use a program to compare the number with its reverse.

Step-by-step explanation:

To check whether a 4-digit number is a palindrome or not, we can use a program to compare the number with its reverse. Here's a program in Python that does exactly that:

num = input('Enter a 4-digit number: ')

reverse_num = num[::-1]
if num == reverse_num:
print('The number is a palindrome!')
else:
print('The number is not a palindrome!')

In this program, the input() function is used to take the user's input, which is stored in the variable num. The [::-1] syntax is used to reverse the string, and then it is compared with the original input using an if statement. If the two are equal, the number is a palindrome; otherwise, it is not.

User Allah
by
7.1k points