Advertisement
immanual1

palindrome.py

Jan 13th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. def is_palindrome(n):
  2. original = n
  3. reverse = 0
  4. while n > 0:
  5. reverse = reverse * 10 + n % 10
  6. n //= 10
  7. return original == reverse
  8.  
  9. num = int(input("Enter a number: "))
  10. if is_palindrome(num):
  11. print(num, "is a palindrome.")
  12. else:
  13. print(num, "is not a palindrome.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement