Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions strings/palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,32 @@
benchmark_function("is_palindrome_recursive")
# finished 500,000 runs in 2.08679 seconds
benchmark_function("is_palindrome_traversal")

# 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.

Check failure on line 106 in strings/palindrome.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

strings/palindrome.py:106:89: E501 Line too long (147 > 88)
N = int(
input("Enter yor number: ")
) # our user will provide algorithm with a number which will be converted to int.


def isPalindrome(

Check failure on line 112 in strings/palindrome.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

strings/palindrome.py:112:5: N802 Function name `isPalindrome` should be lowercase
N,

Check failure on line 113 in strings/palindrome.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N803)

strings/palindrome.py:113:5: N803 Argument name `N` should be lowercase
): # Function which will check if our provided input is a palindrom or not.
reverse = 0
original = N # storing the value of provided input

while N > 0:
digit = (
N % 10
) # Abstracting the values from ones place and hence moving forward
reverse = reverse * 10 + digit # reversing the number
N = N // 10

Check failure on line 123 in strings/palindrome.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

strings/palindrome.py:123:9: N806 Variable `N` in function should be lowercase

if (
reverse == original
): # Checking if the number thus obtained is equal to the provided number or not
return True # if it is then returning True
else:
return False # else False

Check failure on line 130 in strings/palindrome.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (SIM103)

strings/palindrome.py:125:5: SIM103 Return the condition directly


print(isPalindrome(N)) # calling the function and hence print the bool answer.
Loading