Oct-07-2017, 07:12 PM
I have a homework assignment that wants me to get a user input string, reverse it, then remove all punctuation. After that, I must compare original string to reversed string and output if the initial input is or is not a palindrome.
I have gotten it for the most part (I think). The problem is, I can only find the strip() method when we have not even covered it. In fact, we haven't covered anything on removing punctuation. So I ask of you, "Will you point me in the right direction so that I can remove all punctuation without strip() or any other devices that I have not covered?"
My research has put me at a dead-end. I need your help. I am not sure what to do next. Truth is, I think I should strip it before I reverse it, but honestly, I don't think I can use strip() at all. My head hurts. Please help!
I have gotten it for the most part (I think). The problem is, I can only find the strip() method when we have not even covered it. In fact, we haven't covered anything on removing punctuation. So I ask of you, "Will you point me in the right direction so that I can remove all punctuation without strip() or any other devices that I have not covered?"
My research has put me at a dead-end. I need your help. I am not sure what to do next. Truth is, I think I should strip it before I reverse it, but honestly, I don't think I can use strip() at all. My head hurts. Please help!
# Palindrome (Program 3) # string to test for myprogramminglab # A Man, A Plan, A Canal: Panama # Get user input for string wordPhrase = input("Enter a word or phrase: \n") # Make input lowercase wordPhrase = wordPhrase.lower() # Reverse input revWord = "" for ch in wordPhrase: revWord = ch + revWord # strip punctuation from revWord strIpped = [l.strip(':') for l in revWord] # if/else for "is" or "is not" a palindrome if wordPhrase == revWord: print(wordPhrase + " is a palindrome.") else: print(wordPhrase + " is not a palindrome.")