A palindrome reads the same forwards and backwards, like level. Read a lowercase word and print YES if it is a palindrome, otherwise NO.
What to build
A check that compares a word with its reverse.
Requirements
- Read the word.
- Print
YESif it reads the same in both directions, andNOotherwise.
Input
One lowercase word.
Output
YES or NO.
Constraints
The word has lowercase letters only.
Example
Input:
level
Output:
YES
Why it works
word[::-1] gives the word backwards, so one comparison answers the question.
Examples
Example 1 · Input
level
Expected output
YES
Example 2 · Input
python
Expected output
NO
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
word[::-1] is the word backwards.
Solution
Show one correct solution (try it yourself first)
word = input()
print("YES" if word == word[::-1] else "NO")