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 prime_test(n) 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 prime_test(n).
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 prime_test(n) which should use a for loop and range() to check for divisors of nn.
After your prime_test(n) function has returned its result, you should this value to display your result:
Enter an integer >1: 447101447101 is prime.
or
Enter an integer >1: 123458757123458757 is not prime.
or
Enter an integer >1: 2281850322818503 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 99,194,853,094,755,497 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 folder/directory as your is_it_prime.py program, then run this code. It will check the correctness of your is_it_prime.py calculations within a small range of values (up to 1000). To download, ctrl-click (macOS) or right click (Windows) and select Save File As...(details 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!