Skip to content

Commit 2972579

Browse files
committed
i have added a fubnction checking if an integer is a palindrome or not
1 parent 6e24935 commit 2972579

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

strings/palindrome.py

+18
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,21 @@ def benchmark_function(name: str) -> None:
102102
benchmark_function("is_palindrome_recursive")
103103
# finished 500,000 runs in 2.08679 seconds
104104
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.

0 commit comments

Comments
 (0)