The code works perfect. :slight_smile:

I wonder, even if i write (x - 1) or just x when representing the range function both of them works perfect in either case.
To my knowledge,

lets suppose x = 10
range(2, x) will give (2,3,4,5,6,7,8,9)

and range (2, x - 1) will give (2,3,4,5,6,7,8)

then why does everyone mentions x - 1 when i try to go through all the solutions to cross check. Thanks for the help in advance. :slight_smile:

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


The full range would make more sense on first look. However, when we think about it, we could stop anywhere after x / 2 plus 1 for good measure.

The largest number that can be divided into a number is no more than half of that number.


Exactly! Thanks for the preciseness. :slight_smile:


2 posts were split to a new topic: Don't understand why lines 6-7 aren't indented