Question: In this homework assignment, you will write a program that prints out pairs of twin primes. Since that may sound a bit overwhelming, we've broken
In this homework assignment, you will write a program that prints out pairs of twin primes.
Since that may sound a bit overwhelming, we've broken up this process into a few steps for you.
First, write a function that determines whether or not a number is a prime number. As a
reminder, a prime number is a number that only has two factors: and itself. Note that
and are not prime numbers, and that is a prime number. You can not look up any
formulas or algorithms online to determine if a number is prime. You must use the
information above to write your own algorithm to determine if a number is prime.
Your function must have the following function header:
def isprimenum
As seen from the function header, the function should be named isprime and have
one parameter, num. This function should return a boolean that indicates whether or not
the number is prime. More specifically, if the number passed into this function is prime,
the function should return True. If the number passed into this function is not prime,
the function should return False.
After writing the isprime function, it's time to begin testing! Programmers often
write test cases to ensure that their code has been written correctly. While there are
useful Python frameworks designed specifically for testing such as unittest, which you
are welcome to read more about if you are interested we will not be using them in this
class due to time constraints that don't allow us to fit this into our curriculum Instead,
we will test our code by calling the functions we want to test in main, printing out the
functions' return values, and manually checking that the functions return what we
expect.
Write a main function that has three test cases for isprime. Each test case should call
isprime with a different argument and print out the return value of the function call.
Then, you should manually check that the return value is correct according to whether
the argument is actually prime or not
A comprehensive group of test cases will test different paths of execution that the
isprime function may take. Put another way, all the test cases should not use just
prime numbers or just nonprime numbers as the arguments, since then your test cases
are never checking that the function behaves correctly in the other situation. We will be
grading this part of the assignment manually and checking that you wrote a
comprehensive group of test cases.
If your code fails the test cases, now is the time to go back and fix your isprime
function! You will use the is prime function in the next part of this assignment, so
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
