Palindrome
Definition of palindrome is any number/string which is same after getting reversed is palindrome.
Example - 123321, 131, GAG, EYE etc
Below is the python code to check if a string or number is palindrome
CODE
def check_palindrome(input_value):
is_pallindrome = False
letters_of_input = list(input_value)
string_size = len(letters_of_input)
start_index = 0
end_index = string_size - 1
mid_index = int(string_size/2) - 1
while start_index <= mid_index:
if input_value[start_index] == input_value[end_index]:
is_pallindrome = True
else:
is_pallindrome = False
break
start_index = start_index+1
end_index =end_index-1
print(input_value[start_index],input_value[end_index])
return is_pallindrome
input_data = input("Enter a number/string to check if its palindrome: ")
if check_palindrome(input_data) == True:
print("The input value {} is palindrome".format(input_data))
else:
print("The input value {} is not palindrome".format(input_data))
No comments:
Post a Comment