yield_hw-2
View on GitHub | Download Local
Extracted Content (for search)
Click to view slide text
CS3323 Homework 7 – Python yield We call an integer SuPrP2 if it can be written as a sum of a prime and a power of 2. For example, 15 is a SuPrP2 since 15 = 13 + 21 , but 16 is not.
- Write a Python generator that yields all power of two starting from 1 = 20 .
- Write a Python generator that on an input positive integer n, yields all SuPrP2 numbers in the increasing order that are greater than n.
- Let N be your student ID number. Use the generator to find 20 consecutive SuPrP2 numbers right after N . Note:
- You may use, with clear citations, functions which we developed in class, but you should not import any modules.
- You need to pay attention to efficiency of the program as numbers involved are quite large.
- Please include the answer to the question (3) as comments in the source code, and submit the source code as text file.
1