Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write is_palindrome(text) by recursion. A text is a palindrome if its first and last letters are the same and the text between them is a palindrome. What are the answers for level, python and noon?
Compare the two ends, then check the middle.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Base case. A text of one letter or none is a palindrome: True.
Recursive cases. If the first and last letters differ, it is False. Otherwise check the text between them: text[1:-1].
level: l = l, then eve: e = e, then v: True.python: p and n differ: False.noon: n = n, then oo: o = o, then nothing: True.Log in to join the discussion.
Loading…
With Standard, you also open 10 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.