0% found this document useful (0 votes)
1 views4 pages

Python Problem Solve

The document explains how to check if a string is a palindrome, which means it reads the same forward and backward. It provides examples of both palindromic and non-palindromic strings and outlines a step-by-step solution using a while loop to reverse the string for comparison. Additionally, it suggests a more concise method using slicing and poses a question about handling case-insensitive palindromes.

Uploaded by

Ngan Pham
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Python Problem Solve

The document explains how to check if a string is a palindrome, which means it reads the same forward and backward. It provides examples of both palindromic and non-palindromic strings and outlines a step-by-step solution using a while loop to reverse the string for comparison. Additionally, it suggests a more concise method using slicing and poses a question about handling case-insensitive palindromes.

Uploaded by

Ngan Pham
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Problem Solve

Abdullah Shayed

🔍 Palindrome Checker
📝 Check if a string reads the same forward & backward
What in Palindrome ?
A palindrome is a word that reads the same forward and backward.

For Example →
"NaN" →"NaN" Palindrome ✅
"racecar" →"racecar" Palindrome ✅
"rotator" →"rotator" Palindrome ✅
"None" →"Enon" Not Palindrome ❌
"Hello" →"Olleh" Not Palindrome ❌

Let Break Down The problem →


Reverse the given string.
Compare the reversed string with the original string.
Abdullah Shayed

If they are the same → it’s a palindrome.


Otherwise → not a palindrome.
Step-by-Step Solution →
Take input from the user.
Initialize an empty string backwardStr.
Reverse the string using a while loop.
Compare the original string and the reversed string.
Print the result based on the comparison.

Input: NaN
Output: NaN is a Palindrome Word
Abdullah Shayed

Input: racecar
Output: racecar is a Palindrome Word

Input: rotator
Output: rotator is a Palindrome Word

Input: None
Output: None isn't a Palindrome Word

Input: Hello
Output: Hello isn't a Palindrome Word
I solved it using a `while` loop to reverse the string and then
compared it with the original string.
💡 Pro Tip: You can also solve this in one line using slicing!
💬 How would you handle case-insensitive palindromes like `"RaceCar"`?

Thanks For Reading


Abdullah Shayed

If you think it’s helpful —


Please Follow Me For More Dev Tips

#Python #Palindrome #ProblemSolving #LearnToCode #PythonTips

You might also like