forked from Dadsaster/python_class
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.py
More file actions
26 lines (22 loc) · 893 Bytes
/
5.py
File metadata and controls
26 lines (22 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Return true if the given string is a palindrome. Otherwise, return false.
# A palindrome is a word or sentence that's spelled the same way both
# forward and backward, ignoring punctuation, case, and spacing.
# You'll need to remove punctuation and turn everything lower case in order
# to check for palindromes.
# We'll pass strings with varying formats, such as "racecar", "RaceCar",
# and "race CAR" among others.
def palindrome(string):
# make string lower case
# loop through string
new_string = ''
for char in string.lower():
if char in 'abcdefghijklmnopqrstuvwxyz':
new_string = new_string + char
print(new_string)
# test if character is in [a-z] - keep
# reverse new string
# compare to forward string
# return True
# print(palindrome("eye")) # True
print(palindrome("A man, a plan, a canal. Panama")) # True
# print(palindrome("one")) # False