# Project 3: Project Euler Knockoff
from math import sqrt, ceil
# define function for checking if a number is prime
def is_prime(n):
"""A prime number can only be evenly
divided by one and itself
Examples: 2, 3, 5, 7, 11, 13...
Note! 0 and 1 are NOT primes!"""
if n==0 or n==1:
return False
else:
for i in range(2, ceil(sqrt(n))):
if n % i == 0:
return False
return True
# define function for generating a fibonacci sequence
def fibgen():
"""Fibonacci sequence is defined by every next term
being the sum of the two previous terms.
Example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34"""
a, b = 0, 1
while True:
yield a
b = a + b
yield b
a = a + b
# create a generator object from the generator function
x = fibgen()
# initialize an empty list to keep track of the fib primes
fibprimes = []
# generate with a while loop until we have 12
while len(fibprimes) < 12:
# call the next value from the generator function
check = next(x)
# check to see if it's prime, then print it
if is_prime(check):
fibprimes.append(check)
print(check)