Instructions
Requirements and Specifications
Source Code
# import turtle
import turtle
# Define a function that draw the square
def draw_square(t, x, y, color_value, square_size):
t.penup()
t.goto(x,y)
t.pendown()
t.fillcolor(color_value)
t.begin_fill()
for i in range(4):
t.forward(square_size)
t.right(90)
t.end_fill()
# Define size of square
SIZE = 40 #in pixels
# Number of squares per row
SQUARES = 10
# Calculate size of each square
square_size = SIZE/SQUARES
# Create screen
turtle.setup(SIZE, SIZE)
turtle.speed(0)
s = turtle.getscreen()
# Define starting color
color_value = "black"
squares_row = 0
rows = 0
squares = 0
x = 0
y = 0
# Set up turtle
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
while True:
draw_square(turtle, x, y, color_value, square_size)
if color_value == "red":
color_value = "black"
else:
color_value = "red"
x += square_size
squares_row += 1
if squares_row == SQUARES:
if color_value == "red":
color_value = "black"
else:
color_value = "red"
x = 0
y += square_size
squares_row = 0
rows += 1
squares += 1
if squares == SQUARES*SQUARES:
break
s.exitonclick()
# Ask user for age
age = int(input("Enter your age: "))
if age >= 18: # has enough age to vote
print("You are old enough to vote!")
else:
print("You are not old enough to vote.")