Question: 6. (20pt) Write a Python iterator primes (N) that generates, using yield, all prime numbers up to N. The code should behave like this: def


6. (20pt) Write a Python iterator primes (N) that generates, using yield, all prime numbers up to N. The code should behave like this: def primes (N): ... # fill in the body of the function n = primes (11) print(next(n)) # 2 print(next(n)) # 3 print(next(n)) # 5 print (next(n)) # 7 print(next(n)) # 11 print(next(n)) # raises StopIteration Submit your code in a file primes.py. Your code should run in Python 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
