Q6: Write code using the turtle module to draw a rectangle of consecutive ints from the int in the upper left to the int in the lower right. If the int is one of a pair of twin primes, the twin primes should be red. If the int is a prime (but not a twin prime), the int should be blue. Otherwise, the int is black.
This is my code so far:
import turtle
UL = 4686
numRows = 33
numCols = 51
max_number = UL + numRows*numCols - 1
numbers = [ list(range(UL + (row *numCols), UL + (row*numCols) + numCols)) for row in
range(numRows)]
turtle.tracer (0,0)
t = turtle.Turtle ()
## Question 2:
def count_twinprime (UL, max_number):
count = 0
for a in range (UL, max_number):
b = a + 2
if (is_prime(a) and is_prime(b)):
count += 1
print ("Number of twin primes are: ", count)
print ('Q2')
twinPrimes = count_twinprime(UL, max_number)
Question 6:
def drawRectangle(tObj, size, text, color):
tObj.penup()
tObj.forward(size//2)
tObj.color(color)
tObj.write(number, align='center', font=("Arial", 8, "normal"))
tObj.forward(-size//2)
tObj.pendown()
tObj.color('black')
for side in range(4):
tObj.forward(size)
tObj.left(90)
print("Q6:\tSee rectangle of ints showing primes & twin primes\n")
twinPrime = count_twinprime (UL, max_number)
size = 30
number = UL
for row in range(numRows):
for col in range(numCols):
if number in twinPrimes:
color = 'red'
elif is_prime(number):
color = 'blue'
else:
color = 'black'
drawRectangle(t, size, number, color)
t.forward(size)
number += 1
t.penup()
t.setx(0)
t.right(90)
t.forward(size)
t.left(90)
t.hideturtle()
turtle.update()
I keep getting this how do I solve it?
Traceback (most recent call last):
File "/Users/bk/Documents/csc_proj.py", line 109, in
<module>
if number in twinPrimes:
TypeError: argument of type 'NoneType' is not iterable