In this activity, you are going to be thinking about how to test the isPrime function which takes a number and tests if it is prime. For each question, we will describe a mistake that the programmer might have made in writing isPrime. We will imagine that there is a check function that takes the number with which to test isPrime, and the expected answer (True or False). The check function might look something like this:
def check(num, expected):
if isPrime(num) != expected:
print("isPrime("+str(num)+") did not work")
pass
pass
For each question, your answer should be a single call to check that identifies the problem described in the question prompt. For example, if the question prompt suggests that isPrime(3) does not work correctly, you could answer
check(3, True)
to identify the mistake.
Question 1
Suppose the programmer writing isPrime mistakenly thought that all prime numbers were odd, so they first checked if the number passed in is even, and if so, returned False right away.
Question 2
Suppose the programmer could not think of a general algorithm so instead they just checked several specific case with the first several prime numbers:
if (num == 2):
return True
if (num == 3):
return True
return False
What I have tried:
I am trying but not getting the correct answer please help.