bslatkin / effectivepython

Effective Python: Second Edition — Source Code and Errata for the Book
https://effectivepython.com
2.24k stars 718 forks source link

Item #9: Incorrect indentation for return statement in coprime_alternate function #103

Closed veganjay closed 4 months ago

veganjay commented 3 years ago

The coprime_alternate function includes extra indentation on the return statement, and the assert statements fail:

def coprime_alternate(a, b):
    is_coprime = True
    for i in range(2, min(a, b) + 1):
        if a % i == 0 and b % i == 0:
            is_coprime = False
            break
        return is_coprime

Instead it should be:

def coprime_alternate(a, b):
    is_coprime = True
    for i in range(2, min(a, b) + 1):
        if a % i == 0 and b % i == 0:
            is_coprime = False
            break
    return is_coprime
bslatkin commented 4 months ago

Thank you for the report! It appears to be correct in the example code https://github.com/bslatkin/effectivepython/blob/4ae6f3141291ea137eb29a245bf889dbc8091713/example_code/item_09.py#L104 so there must have been something wrong with the post-production here. I'll watch out for it!