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 projects/008-word-by-word-palindromes/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import string
counter = 0
is_palindrome = True

user_input = input('Insert a string: ')
user_input = user_input.casefold()

for punctuation in string.punctuation:
user_input = user_input.replace(punctuation, '')

cleaned_list = user_input.split()
words_in_list = len(cleaned_list)-1

for word in cleaned_list:
if word == cleaned_list[(words_in_list)-counter]:
counter += 1
else:
is_palindrome = False
break

if is_palindrome == True:
print('The string is palindrome')

else:
print('The string is not palindrome')