Question: The program Write a program that prompts the user for an integer, nn , greater than or equal to two, and reports whether nn is
The program
Write a program that prompts the user for an integer, nn greater than or equal to two, and reports whether nn is prime or not.
You should define a single function called primetestn which takes some positive integer n and returns a Boolean: True if n is prime, and False otherwise. This function should work with any valid n and must not depend on anything other than the n you pass in Make sure your function is called primetestn
Your program not the function should prompt for an integer greater than or equal to two. Be sure to validate input using a while loop.
Once you have a number from user input, your program should call primetestn which should use a for loop and range to check for divisors of nn
After your primetestn function has returned its result, you should this value to display your result:
Enter an integer : is prime.
or
Enter an integer : is not prime.
or
Enter an integer : is prime.
The autograder will look for the word not in your answer. If it finds the word not it will assume you mean not prime If it does not find the word not it will assume you have found that nn is indeed prime.
There are a couple little shortcuts you can use, if you wish not required Theres no need to test any divisors that are greater than nn You can also check two, and then skip over all even numbers thereafter when checking for divisors. Feel free to import math if you wish to use this fact in your function but its not necessary You may not import any other modules for this program.
Test your program with a variety of inputs to ensure it works as intended.
There are a lot of solutions to this out on the internet and I have a modest collection of these ready at hand Youll learn more if you solve it yourself, so no peeking!
Is prime? How long did your program take?
If you wish to test your program locally, you can use this code: test program. Download this file and put it in the same folderdirectory as your isitprime.py program, then run this code. It will check the correctness of your isitprime.py calculations within a small range of values up to To download, ctrlclick macOS or right click Windows and select Save File Asdetails may vary slightly depending on your browser
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
