Python bootcamp · Lab 15

Palindrome check

mediumStrings10 minLesson: Slicing Strings

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read one word and print yes if it reads the same forwards and backwards, otherwise no.

Ignore case: Level should count as a palindrome.

Input. One line: a word.

Output. yes or no (lowercase).

Examples

Example 1 — Case-insensitive: Level == leveL reversed.
Input
Level
Output
yes
Example 2
Input
python
Output
no
Hint
  1. Lowercase the word first so case does not break the comparison.
  2. A string equals its own reverse exactly when it is a palindrome: s == s[::-1].
Show correct code

Peek only after you have tried. You can still Check your own version.

s = input().strip().lower()
print("yes" if s == s[::-1] else "no")
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.