# ------------------------------------------------------------
# Modules
# ------------------------------------------------------------
import turtle
# ------------------------------------------------------------
# Constants
# ------------------------------------------------------------
FILENAME = "ukraine.txt"
OFFSET_X = -140
OFFSET_Y = 100
SCALE_X = 1.4
SCALE_Y = 1.8
# ------------------------------------------------------------
# Global variables
# ------------------------------------------------------------
f = None
lines = []
line = ""
x = 0
y = 0
t = None
first_point = True
# ------------------------------------------------------------
# Main program
# ------------------------------------------------------------
# open the file
f = open(FILENAME)
lines = f.read().split("\n")
f.close()
first_point = True
t = turtle.Turtle()
# plot each point
for line in lines:
# extract x and y coordinates
if "," in line:
x,y = line.split(",")
x = int(x) + OFFSET_X
y = int(y) + OFFSET_Y
x *= SCALE_X
y *= SCALE_Y
t.goto(x,y)
# treat the first point differently so we can start filling in the shape
if first_point:
t.pendown()
t.begin_fill()
first_point = False
# treat an empty line differently so we can fill in a shape
elif line == "":
t.end_fill()
# assume anything else is the colour to draw a shape
else:
t.color(line)
t.penup()
first_point = True
# draw the text
t.penup()
t.goto(0, 50)
t.write("We stand with", font=("Arial", 20), align="center")
t.goto(0,0)
t.color("#005bbc")
t.write("Ukraine", font=("Arial", 20), align="center")
# Challenges:
# 1) Draw a black rectangle behind the image
# 2) Make the text bigger and change the font
# 3) Adjust the offset and scale so that the image is in the middle of the screen
# ------------------------------------------------------------
# Modules
# ------------------------------------------------------------
import turtle
# ------------------------------------------------------------
# Constants
# ------------------------------------------------------------
FILENAME = "ukraine.txt"
OFFSET_X = -140
OFFSET_Y = 100
SCALE_X = 1.4
SCALE_Y = 1.8
# ------------------------------------------------------------
# Global variables
# ------------------------------------------------------------
f = None
lines = []
line = ""
x = 0
y = 0
t = None
first_point = True
# ------------------------------------------------------------
# Main program
# ------------------------------------------------------------
# open the file
f = open(FILENAME)
lines = f.read().split("\n")
f.close()
first_point = True
t = turtle.Turtle()
# plot each point
for line in lines:
# extract x and y coordinates
if "," in line:
x,y = line.split(",")
x = int(x) + OFFSET_X
y = int(y) + OFFSET_Y
x *= SCALE_X
y *= SCALE_Y
t.goto(x,y)
# treat the first point differently so we can start filling in the shape
if first_point:
t.pendown()
t.begin_fill()
first_point = False
# treat an empty line differently so we can fill in a shape
elif line == "":
t.end_fill()
# assume anything else is the colour to draw a shape
else:
t.color(line)
t.penup()
first_point = True
# draw the text
t.penup()
t.goto(0, 50)
t.write("We stand with", font=("Arial", 20), align="center")
t.goto(0,0)
t.color("#005bbc")
t.write("Ukraine", font=("Arial", 20), align="center")
# Challenges:
# 1) Draw a black rectangle behind the image
# 2) Make the text bigger and change the font
# 3) Adjust the offset and scale so that the image is in the middle of the screen
Write each prediction of what the program will output.
You can also predict variable values e.g. a = 10
This code has been sabotaged with some common mistakes. Can you find and fix them all?
Click on the button to add 5 more errors to the code
You get more points for each python skill you use from the keywords section
Click on "tests" to see a description of which python skills to aim for and keep track of which ones you've already used