Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(10 pts) is prime: Re-write the is_prime function (given here) in one statement of code. Note: one statement, not one line of code. You can
(10 pts) is prime: Re-write the is_prime function (given here) in one statement of code. Note: one statement, not "one line of code". You can assume the input will be larger than 2, so no need to worry about special cases. Use a generator expression with one of the built-in functions from week 1, and don't copy random stuf from the internet. Note that the function should contain a generator expression, not be a generator function No Sieve of Eratosthenes, or other unusual stuff. We are not interested in efficiency, the point is to figure out how to do it with the tools you have been given. Think about what the for loop and the test inside really mean in order for it to return True def is_prime(candidate): for n in range(2, candidate): if candidate % n 0: return False return True You can use these to test: >>from HW6 import is_prime >>is_prime (2) True >>is_prime (3) True >is_prime (999979) True >is_prime (53) True >>is_prime (345) False >>is_prime (95) False >is_prime (51) False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started