# Palindrome - the string is the same when reversed
# Example: 121, reverse 121 which is a palindrome number
# Example: MADAM, revere - MADAM, which is a palindrome string.
Start
|
|
|
Define function
|
|
|
Convert number to string
|
|
|
Check if string is same when reversed
|
|
|
Return True if yes
|
|
|
End
def check_palindrome(input):
# Convert the inputber to a string
input_str = str(input)
# Check if the string is the same when reversed
return input_str == input_str[::-1]
# Test the function
print(check_palindrome(121)) # True
print(check_palindrome("MADAM")) # True
print(check_palindrome(123)) # False
print(check_palindrome("Teacher")) # False
No comments:
Post a Comment