Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Learned about string manipulation.
# Determine if text is palindromic

#Changed
## Description

Write a program that asks the user for one or more sentences and then lets the user know if it is a palindrome.
Expand Down Expand Up @@ -59,4 +60,4 @@ You may want to use the `re.sub` function to strip out punctuation and spaces. A

* [Palindrome list](http://www.palindromelist.net/).
* [String type in Python](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str).
* [Regular expression operations](https://docs.python.org/3/library/re.html).
* [Regular expression operations](https://docs.python.org/3/library/re.html).
23 changes: 23 additions & 0 deletions palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

palindrome = input("What's your palindrome? ")


def check_palindrome(palindrome):
# for letter in palindrome:
punc = ['.', ',', ':', ';', "'", "_", "!"]
for punc_remove in punc:
palindrome = palindrome.replace(punc_remove, '')
palindrome = palindrome.lower()
palindrome_reverse = palindrome[::-1]
palindrome_reverse = palindrome_reverse.replace(' ', '')
palindrome = palindrome.replace(' ', '')
if palindrome == palindrome_reverse:
print("is a palindrome")
print(palindrome)
print(palindrome_reverse)
else:
print(palindrome)
print(palindrome_reverse)
print("is not a palindrome")

check_palindrome(palindrome)