Question: Please Re do the palindrome example to check for a palindrome by INCLUDING the good characters instead of excluding the bad ones. import string original_str

Please Re do the palindrome example to check for a palindrome by INCLUDING the good characters instead of excluding the bad ones.

import string

original_str = raw_input('Input a string:') modified_str = original_str.lower() # Get rid of capitals

bad_chars = string.whitespace + string.punctuation # Identify problems

for char in modified_str: if char in bad_chars: # Then it is a bad character modified_str = modified_str.replace(char,'') # Make it nothing.

print 'The original string is: {} \ the modified string is: {} \ the reversed string is: {}'.format(original_str, modified_str,modified_str[::-1])

if modified_str == modified_str[::-1]: print 'This is a palindrome.' else: print 'Tthis is not a palindrome.'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!