Solution Review: Check Whether a Number is Prime
This review explains the solution for the "checking prime" problem.
We'll cover the following...
Solution
Press + to interact
def is_prime(n):"""Tests if a number n is prime."""if n <= 1: # Adding this conditionreturn Falsedivisor = 2while divisor <= n // divisor:if n % divisor == 0:return Falsedivisor += 1return Truen = 1print(is_prime(n))
Explanation
Over here, we have to add in the condition for when n
is less than or equal to 1, as you can see in line 3 of the above code. If n
is either less than or equal ...