Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions