An is_prime that gives wrong results

Code review · Medium · §8.2, §8.6 The math helper as parts

This function is meant to return True if a number is prime and False if it is not. It runs without an error, but it says 9 is prime, and it returns None for 2. Fix just the indentation of one line.

Code to fix

def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, n):
        if n % i == 0:
            return False
        return True

print(is_prime(9), is_prime(2))

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.