+ 1
Palindrome number
Write a program to determine if given number is palindrome or not. Print true if it is palindrome, false otherwise. Palindrome are the numbers for which reverse is exactly same as the original one. For eg. 121
5 Antworten
+ 3
def is_palindrome(n):
return n == n[::-1]
n = input()
print(is_palindrome(n))
+ 2
Similar to the other solution I gave you earlier for your other question, you can use the modulo operator to get the digit in the one's place (n = num % 10) then set this digit to a variable. You can then drop the one's digit by using floor division (num //= 10). Multiply the saved digit by 10 to move it over to prepare the addition of the next number in the one's place. Repeat until num is 0 and the variable hold the reversed value of num. Then return the compared original input value of num (only alter a copy of it to preserve it) to the reversed value of num. If they are equal then the number is a palindrome.
+ 2
Shadoff pretty sure they are needing it done mathematically. Otherwise, I would have offered a 1 liner 😉
+ 1
Here is the hint
def checkPalindrome(num):
#Implement Your Code Here
num = int(input())
isPalindrome = checkPalindrome(num)
if(isPalindrome):
print('true')
else:
print('false')
0
Easy-peasy.
https://code.sololearn.com/cW2HTx9gBu17/?ref=app