Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this code draws a bear made of circles # by reading data from a file to get the parameters for the circle function. Will you
this code draws a bear made of circles
# by reading data from a file to get the parameters for the circle function.
Will you please help me find the error in my code?
# move the pen without leaving a line
def relocateturt x y:
turt.penup
turt.setxx
turt.setyy
turt.setheading
turt.pendown
# draw a circle at the specified position
def circleturt x y radius, color:
SHIFTX
SHIFTY
SCALE
x x SHIFTX
y y SHIFTY
x x SCALE
y y SCALE
radius radius SCALE
relocateturt x y
turt.colorcolor color
turt.beginfill
turt.circleradius
turt.endfill
# draw crosshairs
def crosshairsturt n:
relocateturt n
turt.setheading
turt.forwardn
relocateturt n
turt.setheading
turt.forwardn
def main:
import turtle
wn turtle.Screen
wnbgcolorgray
t turtle.Turtle
twidth
tspeed
thideturtle
crosshairst
try:
with opencirclestxtr as file:
for line in file:
data line.stripsplit
x y radius, color mapfloat data
circlet x y radius, color
except FileNotFoundError:
printError: File 'circles.txt not found."
except ValueError:
printError: Invalid data format in 'circles.txt
try:
printClose the window when done viewing."
turtle.done
except:
printDone
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started