I'm having trouble with this problem that simply return True of False if a number n
, is a palindrome.
Note: wherever I have a ____
indicates where there is a blank that needs to be filled in. There are 2 blank spaces.
def is_palindrome(n):
x, y = n, 0
f = lambda: ____
while x > 0:
x, y = ____ , f()
return y == n
I've spent about an hour on this. I've found out that putting x//10
in the second blank space will allow the function to iterate over the number of digits in n
. It then comes down to the function f
.
Ideally, every time it is called, it should add the last digit in n
to a new number, y
. Thus, if n = 235
, the while loop will iterate 3 times, and each time f()
is called, it should add 5
, 3
, and 2
, to the value y
.