Skip to content

Commit 04cff12

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2972579 commit 04cff12

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

strings/palindrome.py

+25-14
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,32 @@ 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
111105

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
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(
108+
input("Enter yor number: ")
109+
) # our user will provide algorithm with a number which will be converted to int.
110+
116111

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
112+
def isPalindrome(
113+
N,
114+
): # Function which will check if our provided input is a palindrom or not.
115+
reverse = 0
116+
original = N # storing the value of provided input
117+
118+
while N > 0:
119+
digit = (
120+
N % 10
121+
) # Abstracting the values from ones place and hence moving forward
122+
reverse = reverse * 10 + digit # reversing the number
123+
N = N // 10
124+
125+
if (
126+
reverse == original
127+
): # Checking if the number thus obtained is equal to the provided number or not
128+
return True # if it is then returning True
119129
else:
120-
return False #else False
130+
return False # else False
131+
121132

122-
print(isPalindrome(N)) #calling the function and hence print the bool answer.
133+
print(isPalindrome(N)) # calling the function and hence print the bool answer.

0 commit comments

Comments
 (0)