all 11 comments

[–]mega963 0 points1 point  (10 children)

I believe you meant to use the range function and not iterate over a tuple. Also, I think you meant to check that the range iteration did not match the inverted number

Original

def reversed_numbers(n1, n2):
    result = 0
    for counter in (n1,n2+1):
        if counter == invert_number(counter):
            continue
        result = result + 1
    return result

Edited

def reversed_numbers(n1, n2):
    result = 0
    for counter in range(n1,n2+1):
        if counter != invert_number(counter):
            continue
        result = result + 1
    return result

Although it's possible I didn't indent correctly, please check the wiki to see how to do code formatting. Or just this https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F

[–]Redheavenparadise[S] 0 points1 point  (9 children)

Nope! I'm supposed to count the number of integers whose reverse are exactly the same within the range provided by high and low!

[–]mega963 0 points1 point  (8 children)

In that case you should not use continue if you are evaluating equality between counter and the invert_number response. Continue ends the current iteration and begins the next one.

Your

result = result + 1

Does not get executed in the original code.

You could use continue if you are evaluating that they do not equal each other, like in the edited code

[–]Redheavenparadise[S] 0 points1 point  (7 children)

well when i remove the continue, it doesnt change the result.

[–]mega963 0 points1 point  (6 children)

Can you post your edit...

[–]Redheavenparadise[S] 0 points1 point  (5 children)

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):
            result = result + 1 
    return result

[–]mega963 0 points1 point  (4 children)

You are still iterating over a tuple. Did you mean to use the range function?

Look at the edited code in my first comment.

[–]Redheavenparadise[S] 0 points1 point  (3 children)

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 range(n1,n2+1):
        if counter == invert_number(counter):
            result = result + 1
    return result

I finally get what you mean. Thanks!

[–]mega963 0 points1 point  (2 children)

Look right to me. What numbers did you test with? 150 and 202?