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
22 changes: 22 additions & 0 deletions projects/018-is-a-string-a-palindrome/python/main.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you optimize this code?

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
user_word = input('Insert a word: ')

letters_counter = len(user_word)
half_word = letters_counter//2
reverse_counter = letters_counter - 1
counter = 0
is_palindrome = False

while counter < half_word:
if user_word[counter] == user_word[reverse_counter]:
counter += 1
reverse_counter -= 1
is_palindrome = True

else:
break

if not is_palindrome:
print(f'{user_word} is not palindrome')

else:
print (f'{user_word} is palindrome')