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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
