diff --git a/learn.txt b/learn.txt new file mode 100644 index 0000000..969ac6a --- /dev/null +++ b/learn.txt @@ -0,0 +1 @@ +This is a file sent for learning purposes diff --git a/palindrome.py b/palindrome.py new file mode 100644 index 0000000..d0da546 --- /dev/null +++ b/palindrome.py @@ -0,0 +1,35 @@ +import re + +print("I am a program that determines if a word or phrase is a palindrome.") + + +initial = input("\nType your word or phrase here: ") + +def phrase(initial): +# save initial input for the output so that sentences dont appear jumbled + phrase = initial + + # change all letters to lowercase in string + phrase = phrase.lower() + + # ignore all special characters and numbers + phrase = re.sub('[0-9]+[\c]','',phrase) + + # remove spaces in string + phrase = phrase.replace(' ','') + return(phrase) + + + + +def forward_equals_backward(phrase): + # take the altered string and reverses it + b = phrase[::-1] + if phrase == '': + print("Invalid argument please enter a word or a phrase") + elif phrase == b: + print("\n{}".format(initial) + " is a palindrome") + else: + print("\n{}".format(initial) + " is not a palindrome") + +forward_equals_backward(initial)