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

You can use these to test:

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

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.

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)


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
Get step-by-step solutions from verified subject matter experts
