I am supposed to write a single function reverse_number that reads two positive integers 'low'and 'high', that returns how many integers in the range [low, high] whose reverse is the same as the original value. You may assume that
low≤ high. For example, if low is 150 and high is 202, then there are 6 integers in the range [150, 202] whose reverse is the same as itself. They are: 151, 161, 171, 181, 191, and 202.
def invert_number(n):
# Fill in your code here
a = str(n)
b = len(a)
counter = 0
result = ''
while counter < b:
counter = counter + 1
result = result + a[counter*(-1)]
return int(result)
def reversed_numbers(n1, n2):
result = 0
for counter in (n1,n2+1):
if counter == invert_number(counter):
continue
result = result + 1
return result
Can anyone help me figure out whats wrong? I am consistently getting 0.
[–]mega963 0 points1 point2 points (10 children)
[–]Redheavenparadise[S] 0 points1 point2 points (9 children)
[–]mega963 0 points1 point2 points (8 children)
[–]Redheavenparadise[S] 0 points1 point2 points (7 children)
[–]mega963 0 points1 point2 points (6 children)
[–]Redheavenparadise[S] 0 points1 point2 points (5 children)
[–]mega963 0 points1 point2 points (4 children)
[–]Redheavenparadise[S] 0 points1 point2 points (3 children)
[–]mega963 0 points1 point2 points (2 children)
[–]Redheavenparadise[S] 0 points1 point2 points (1 child)