1

The problem is trying to use strings to prove whether a word or phrase is a palindrome.

def is_palindrome(input_string):

    left = 0

    right = len(input_string) - 1

    while left < right:
        if input_string[left] != input_string[right]:
            return False
        left += 1
        right -= 1
    
    return True 

This what I attempted to do but when typing in my_palindrome("race car") it was proven false when it is supposed to be proven true. Need help on finding code to add to this to make punctuation and capitalization negligible.

Rohith Nambiar
  • 2,957
  • 4
  • 17
  • 37
  • Does this answer your question? [How to remove punctuation in python?](https://stackoverflow.com/questions/53664775/how-to-remove-punctuation-in-python) – Alexei Levenkov Mar 26 '22 at 04:27
  • To remove spaces - https://stackoverflow.com/questions/8270092/remove-all-whitespace-in-a-string, to lowercase - https://stackoverflow.com/questions/6067692/basic-python-question-on-string-operations-example-string-lowercase – Alexei Levenkov Mar 26 '22 at 04:29

1 Answers1

1

For characters that aren't letters, there is a string function called .isalpha() that returns True if the string contains only alphabetic characters, False otherwise. You'll need to iterate over each character of the string, retaining only the characters that pass this check.

To make your function case-insensitive, you can use .upper() or .lower(), which returns the string with all the letters upper/lowercased, respectively.

Note that this answer is deliberately incomplete, (i.e. no code), per the recommendations here. If, after several days from the posting of this answer, you're still stuck, post a comment and I can advise further.

BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33