Mary C.

asked • 10/13/20

Removing punctuation in python and changing to all lower case

The code below takes a string and checks to see if it's a palindrome. Write a function that takes in the input string and removes the spaces, returning a string without spaces. Try it first on your own first but if you get stuck please look on-line (just cite your references). Python has many built-in methods for string manipulation, or write it with a for loop. Bonus points for removing punctuation and changing all text lower case.

My code so far:


orig_text = input("Enter a string to check if it is a palindrome: ")


if orig_text.replace(" ", "") == orig_text.replace(" ", "")[::-1]:

print(orig_text.replace(" ", ""),"sides reversed is",orig_text.replace(" ", "")[::-1], "\nso it is a palindrome."+ res)

else:

print(orig_text.replace(" ", ""), "is not a palindrome."+ res)

1 Expert Answer

By:

Patrick B. answered • 10/15/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.