-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.py
34 lines (28 loc) · 824 Bytes
/
test2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# def make_word():
# word = ""
# for ch in "spam":
# word +=ch
# yield word
# Finding prime numbers is a common coding interview task.
# The given code defines a function isPrime(x), which returns True if x is prime.
# You need to create a generator function primeGenerator(), that will take two numbers as arguments, and use the isPrime() function to output the prime numbers in the given range (between the two arguments).
# Sample Input
# 10
# 20
def isPrime(x):
if x < 2:
return False
elif x == 2:
return True
for n in range(2, x):
if x % n ==0:
return False
return True
def primeGenerator(a, b):
#your code goes here
for num in range(a, b):
if isPrime(num):
yield num
f = 10
t = 20
print(list(primeGenerator(f, t)))