The problem is here:
Write a version of a palindrome recognizer that accepts a file name from the user, reads each line, and prints the line to the screen if it is a palindrome.
My code so far:
def palindrome_io(file_, mode):
stuff = "`~!@#$%^&*()_-=+[]{}\|;:,<.>/?"
with open(file_, mode) as f:
for line in f:
for char in line:
if char in stuff:
line.replace(char, "")
if line.lower() == line[::-1].lower():
print True
else:
print False
palindrome_io(r'C:\Users\Brian Gunsel\Desktop\test.txt', 'r+')
My input file (test.txt
):
Racecar
paLinDRomE
!Racecar?
Document&
It is returning False
for all of them, when it should be returning True
, False
, True
, False
.