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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started