0% found this document useful (0 votes)
591 views1 page

E1 Fresco Prob3 Correct

This document contains a Python function that takes in two integers, num and val, and returns a generator that yields prime numbers. It first generates a list of all prime numbers between 2 and num. It then splits this list into two lists of alternating primes and yields one list or the other depending on whether val is 1 or 0.

Uploaded by

Kaushik Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
591 views1 page

E1 Fresco Prob3 Correct

This document contains a Python function that takes in two integers, num and val, and returns a generator that yields prime numbers. It first generates a list of all prime numbers between 2 and num. It then splits this list into two lists of alternating primes and yields one list or the other depending on whether val is 1 or 0.

Uploaded by

Kaushik Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#!

/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'primegenerator' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER num
# 2. INTEGER val
#

def primegenerator(num, val):


# Write your code here
arr = []
arr_0= []
arr_1 =[]
for i in range (2,num):
if i >1:
for j in range(2,i):
if i % j == 0:
break
else:
arr.append(i)
for l in range(0,len(arr),2):
arr_0.append(arr[l])
for m in range(1,len(arr),2):
arr_1.append(arr[m])

if val==1:
for item in arr_0:
yield item
if val == 0:
for item1 in arr_1:
yield item1

if __name__ == '__main__':

You might also like