Don't understand why lines 6-7 aren't indented


#1

I don't understand why lines 6-7 aren't indented. When they are--when "else: return True" is in line with "if x % n" like I think it should be, it doesn't work.


Is_prime
#2

Please provide an example of the problem. Thanks.


#3

He was asking for this same code

def is_prime(x):
    if x >= 2:
        for n in range(2, x - 1):
            if x % n == 0:
                return False
        else:
            return True
    else:
        return False

Lines 6 and 7


#4

This else branch is the exclusion group of the for statement. It is not in the range described.


#5

Lessons №7 and №17 in Loops will explain your question, but I advise you to do all lessons and exercises in the order suggested by Codecademy.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.