Question: Python Question 2a . is_prime: Re-write the is_prime function (given here) in one statement of code. Note: one statement, not one line of code. You

Python Question

2a. 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. 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

Python Question 2a. is_prime: Re-write the is_prime function (given here) in one

You can use these to test:

statement of code. Note: one statement, not "one line of code". You

2b. number_4: Create an inexhaustible (never-ending) generator number_4 that always returns the number 4. Use something from itertools

can assume the input will be larger than 2, so no need

2c.reverse_iter: Write a generator function reverse_iter that accepts an iterable sequence and yields the items in reverse order. Don't use built-in functions.

to worry about special cases. No Sieve of Eratosthenes, or other unusual

2d. ReverseIter class: Create an iterator class ReverseIter that takes an iterable sequence and iterates it in the reverse order. (When done, you will appreciate generators from 2c)

stuff. We are not interested in efficiency, the point is to figure

out how to do it with the tools you have been given.

def is_prime(candidate): for n in range(2, candidate): if candidate % n = 0: return False return True

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 Databases Questions!