File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -102,3 +102,21 @@ def benchmark_function(name: str) -> None:
102
102
benchmark_function ("is_palindrome_recursive" )
103
103
# finished 500,000 runs in 2.08679 seconds
104
104
benchmark_function ("is_palindrome_traversal" )
105
+
106
+ #TEST FOR CHECKING A NUMBER/INTEGER TO BE PALINDROME OR NOT. IF THE PROVIDED NUMBER/INTEGER IS PALINDROM THE FUNCTION WILL RETURN TRUE ELSE FALSE.
107
+ N = int (input ("Enter yor number: " ))#our user will provide algorithm with a number which will be converted to int.
108
+ def isPalindrome (N ): #Function which will check if our provided input is a palindrom or not.
109
+ reverse = 0
110
+ original = N #storing the value of provided input
111
+
112
+ while (N > 0 ):
113
+ digit = N % 10 #Abstracting the values from ones place and hence moving forward
114
+ reverse = reverse * 10 + digit #reversing the number
115
+ N = N // 10
116
+
117
+ if reverse == original : #Checking if the number thus obtained is equal to the provided number or not
118
+ return True #if it is then returning True
119
+ else :
120
+ return False #else False
121
+
122
+ print (isPalindrome (N )) #calling the function and hence print the bool answer.
You can’t perform that action at this time.
0 commit comments