<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
I don’t understand why the answer code is right.
<What do you expect to happen instead?>
I expect the range to supposed to be range(2, x) since range will test all the numbers from 2 to x - 1. So if x = 7, the range would be 2, 3, 4, 5, 6. In the answer code they have range(2, x-1) which means the range would be 2, 3, 4, 5. Wouldn’t they have to test 6 as well to see if it is a prime number. With my code, when x = 2, it returns nothing when it should return True. With the answer code, wouldn’t the range become 2, 1, 0?
def is_prime(x): if x < 2: return False else: for n in range(2, x): if x % n == 0: return False else: return True