if x < 2 is never reached, given you placed it inside the loop, which won’t run when
x is less then 2.
which is why you get an error for
I suggest running the code in your head with x=3 which the error message says is the input, and see where you end up. You can also use print statements to print out what’s happening.
why would you do
n += 1? What is the value? the loop will handle the increase of
return None is in the error message, what does this mean?
I don’t know what none error means. and when i remove n+=1 and ran the code . it still shows some error
That’s still the same error message. Think for a while what your program should do when the input is 3, and then follow what your code does, find where it starts doing something differently from what you meant and then you’ll know what needs to be different
3 is prime, so your function should reach a statement that returns True, if you’re returning None, then you aren’t returning True, so you didn’t reach a statement returning True
Run the code in your head. Use prints to verify that you’re running it correctly if you’re not sure.
By default, functions return None, thus, when we get this error message, it means that the return keywords you added, are not reached, what does this say about our program and its design?
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.