Check Palindrome String
Check exact text palindromes with Python string reversal. Students trace equality and see how case, spaces, and punctuation can change the final decision.
1# Take string input2s = input("Enter a string: ")34# Check palindrome5if s == s[::-1]:6 print("Palindrome")7else:8 print("Not a palindrome")
Output
Enter a string: racecar Palindrome Enter a string: hello Not a palindrome
In this one
- Compare exact sequences
- Use a reversed copy
- Retain case and punctuation
How it works
- 1
Read s unchanged.
- 2
Compare it with s[::-1].
- 3
Print the matching palindrome label.
Edge cases
Does empty input pass?
Does empty input pass?
Yes. It equals its own reverse.
Does Level pass?
Does Level pass?
No. The comparison is case-sensitive.
What's going on
The comparison uses s exactly as entered and the new reversed string s[::-1]. No normalization happens before equality.
level passes, while Level fails because uppercase L differs from lowercase l. Spaces and punctuation also participate. Empty and single-character strings pass because their reverse is identical; this is a direct sequence comparison rather than a phrase-cleaning algorithm.
Does empty input pass? Yes. It equals its own reverse.
Does Level pass? No. The comparison is case-sensitive.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What does the code ignore?
Pick an answer to check it.
Question 2
Does empty input pass?
Pick an answer to check it.
Questions people ask
Does empty input pass?
Yes. It equals its own reverse.
Does Level pass?
No. The comparison is case-sensitive.
What does the code ignore?
Nothing in the entered text.
๐Related Content
- ๐
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- ๐
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- ๐ป
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum