53.1k views
3 votes
Write a application that can determine if a 5 digit number you input is a palindrome. If the number is a palindrome then print "The number is a palindrome." If it is not then print "The number is NOT a palindrome"

1 Answer

4 votes

Answer:

Written in Python:

num = int(input("Number: "))

strnum = str(num)

if len(strnum) !=5:

print("Length must be 5")

else:

if(strnum[::-1] == strnum):

print("The number is a palindrome.")

else:

print("The number is NOT palindrome.")

Step-by-step explanation:

This prompts user for input

num = int(input("Number: "))

This converts user input to string

strnum = str(num)

This checks the length of the string

if len(strnum) !=5:

print("Length must be 5") If length is not 5, this prompt is printed

else:If otherwise

if(strnum[::-1] == strnum): The compares the string reversed with the original

print("The number is a palindrome.") If both are the same, this line is executed

else:

print("The number is NOT palindrome.") If otherwise, this line is executed

User Kamil Kuklewski
by
7.9k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.