Fill in the blanks to complete the is_palindrome function. This function checks if a given string is a palindrome. A palindrome is a string that contains the same letters in the same order, whether the word is read from left to right or right to left. Examples of palindromes are words like kayak and radar, and phrases like "Never Odd or Even". The function should ignore blank spaces and capitalization when checking if the given string is a palindrome. Complete this function to return True if the passed string is a palindrome, False if not. ( Image S1Q1 ) Answer: def is_palindrome(input_string): # Two variables are initialized as string date types using empty # quotes: "reverse_string" to hold the "input_string" in reverse # order and "new_string" to hold the "input_string" minus the # spaces between words, if any are found. new_string = "" reverse_string = "" # Complete the for loop to iterate through each letter of the # "input_string" for letter in input_string: # The if-statement checks if the "letter" is not a space. if letter != " ": # If True, add the "letter" to the end of "new_string" and # to the front of "reverse_string". If False (if a space # is detected), no action is needed. Exit the if-block. new_string = new_string + letter reverse_string = letter + reverse_string # Complete the if-statement to compare the "new_string" to the # "reverse_string". Remember that Python is case-sensitive when # creating the string comparison code. if new_string.lower()==reverse_string.lower(): # If True, the "input_string" contains a palindrome. return True # Otherwise, return False. return False print(is_palindrome("Never Odd orEven")) # Should be True print(is_palindrome("abc")) # Should be False print(is_palindrome("kayak")) # Should be True Woohoo! You're quickly becoming the Python string expert!
How confident are you in this answer?