Is prime or not
A prime number can only be divided by itself and 1 without remainders. In this exercise, you will test the function the is_prime()
with unittest
. The function gets a number
and returns True
if it is prime and False
if it is not. It uses the math
package to calculate the square root of the number
. The packages math
and unittest
were already imported for you.
This exercise is part of the course
Introduction to Testing in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
def is_prime(num):
if num == 1: return False
up_limit = int(math.sqrt(num)) + 1
for i in range(2, up_limit):
if num % i == 0:
return False
return True
class TestSuite(unittest.TestCase):
def test_is_prime(self):
# Check that 17 is prime
____