Files
2025-09-15 02:29:40 +05:00

24 lines
902 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TODO здесь писать код
def check_word(word):
length = len(word)
diff = length // 2
for i in range(diff):
if word[i] != word[length - i - 1]:
return False # Плюс к тому же, как только есть несоответствие - прерываем цикл
else:
return True
text = input('Введите слово: ')
if text == text[::-1] and check_word(text):
print('Слово является палиндромом')
else:
print('Слово не является палиндромом')
# Но по данному методу ([::-1]), мы запускаем цикл, который работает len(text) раз
# А если проверять сразу по два символа (check_word()), то это в два раза ускоряет выполнение нашей программы?