0
How to check if word is palindrome or not in python. Using for loop.
You cannot use negative indices You can use only 1 string variables
5 Réponses
+ 6
Shusil
If you need help, you can post the code you're struggling with!
• SEARCH for similar QUESTIONS or ANSWERS before posting
• Include relevant TAGS
• https://www.sololearn.com/post/75089/?ref=app
+ 3
Hint:
Get the string length, decrement it by 1, that's the index of last character to check.
Since you will be checking each character from both end of the string, you'll need half the string length as your loop range limit let it be <half>. Remember to divide with floor division operator to have it an integral value.
Run a for loop <i> with <half> as range limit.
During loop see if character on the i-th position NOT equal to the character on the <half> - <i> position. If so, immediately return False.
If the loop completed then return True.
P.S. Don't ask for code, you won't get it from me XD
+ 2
Can you show us your attempt first?
0
def pal(s):
for i in range(0):
pass
return s == s[::-1]
0
I think while loop work better.Here is an example
https://code.sololearn.com/c18Ltdc8It25/?ref=app