We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c15b8c commit 0340eaaCopy full SHA for 0340eaa
maths/palindrome_number.py
@@ -0,0 +1,27 @@
1
+def is_palindrome(number: int) -> bool:
2
+ """
3
+ Check whether a given integer is a palindrome.
4
+
5
+ A palindrome number reads the same forwards and backwards.
6
7
+ Examples:
8
+ >>> is_palindrome(121)
9
+ True
10
+ >>> is_palindrome(123)
11
+ False
12
13
+ number_str = str(number)
14
+ return number_str == number_str[::-1]
15
16
17
+if __name__ == "__main__":
18
+ user_input = input("Enter a number: ").strip()
19
20
+ if user_input.isdigit():
21
+ number = int(user_input)
22
+ if is_palindrome(number):
23
+ print("The number is a palindrome.")
24
+ else:
25
+ print("The number is not a palindrome.")
26
27
+ print("Please enter a valid non-negative integer.")
0 commit comments