Skip to content
Open
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
25 changes: 25 additions & 0 deletions palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import re


def normalizing(user_string):
"""Removes all nonalpha characters and converts all letters to lowercase"""
search_string = re.compile("[^A-Za-z]")
return re.sub(search_string, '', user_string).lower()


def palindrome(s):
"""Function that determines if the string is a palindrome"""
if len(s) <= 1:
return True
else:
boolean = s[0] == s[-1] and palindrome(s[1:-1])
return(boolean)


sentence = input("Please enter your sentence or sentences: ")


if palindrome(normalizing(sentence)):
print("That is a palindrome")
else:
print("That is not a palindrome")