Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code needs to draw a bear in Python but is not. Can you help me fix my code? Thank you! Import turtle import math

This code needs to draw a bear in Python but is not. Can you help me fix my code? Thank you!
Import turtle
import math
# 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(0)
turt.forward(n)
def main():
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_2

Step: 3

blur-text-image_3

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions