Answered step by step
Verified Expert Solution
Link Copied!

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 relocate(turt, x, y):
turt.penup()
turt.setx(x)
turt.sety(y)
turt.setheading(90)
turt.pendown()
# draw a circle at the specified position
def circle(turt, x, y, radius, color):
SHIFT_X =40
SHIFT_Y =30
SCALE =5
x = x - SHIFT_X
y = y - SHIFT_Y
x = x * SCALE
y = y * SCALE
radius = radius * SCALE
relocate(turt, x, y)
turt.color(color, color)
turt.begin_fill()
turt.circle(radius)
turt.end_fill()
# draw crosshairs
def crosshairs(turt, n):
relocate(turt,0- n/2,0)
turt.setheading(0)
turt.forward(n)
relocate(turt,0,0- n/2)
turt.setheading(90)
turt.forward(n)
def main():
import turtle
wn = turtle.Screen()
wn.bgcolor("gray88")
t = turtle.Turtle()
t.width(2)
t.speed(7)
t.hideturtle()
crosshairs(t,400)
try:
with open("circles.txt","r") as file:
for line in file:
data = line.strip().split()
x, y, radius, color = map(float, data)
circle(t, x, y, radius, color)
except FileNotFoundError:
print("Error: File 'circles.txt' not found.")
except ValueError:
print("Error: Invalid data format in 'circles.txt'.")
try:
print("Close the window when done viewing.")
turtle.done()
except:
print("Done.")
if __name__=="__main__":
main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the employee benefits that are required by law.

Answered: 1 week ago

Question

List the types of incentive plans.

Answered: 1 week ago