Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

=+1 What are the major issues related to international T&D?

Answered: 1 week ago