Last active
May 3, 2019 16:51
-
-
Save ranasaani/e49adf118f3123ae022534236dee9335 to your computer and use it in GitHub Desktop.
Check if a number is a palindrome python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_palindrome(num): | |
rev = 0 | |
duplicate = num | |
while duplicate > 0: | |
r = duplicate % 10 | |
duplicate = int(duplicate / 10) | |
rev = rev * 10 + r % 10 | |
return num == rev | |
is_palindrome(1221) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment