SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:26 | ISBN:978013274719 | Edition: 6

Question

(Palindrome number) Write a program that prompts the user to enter a three-digit integer and determines whether it is a palindrome number. A number is a palindrome if it reads the same from right to left and from left to right. Here is a sample run of this program:

 

Enter a three-digit integer: 121
121 is a palindrome
 

Enter a three-digit integer: 123
123 is not a palindrome
 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#4.26.Palindrome
#Prompt the user to enter a three digit number
number = eval(input("Enter a three digit number:"))
third_digit = number % 10
number1 = number // 10
second_digit = number1 % 10
first_digit = number1 // 10

palindrome =(str(third_digit) + str(second_digit) + str(first_digit))

#check for palindromes
if str(number) == palindrome:
    print("The number is a palindrome.")
else:
    print("The number is not a palindrome.")


 

0 0

Discussions

Post the discussion to improve the above solution.