Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In python Exercise 1 (5 points) Consider the program we developed in class on 09.30 where a turtle moves randomly. Whenever the turtle's distance from
In python
Exercise 1 (5 points) Consider the program we developed in class on 09.30 where a turtle moves randomly. Whenever the turtle's distance from the origin is greater than 200 pixels, the turtle goes back to the origin (see code below) main.py 1 import turtle import random 3 4 t = turtle. Turtle() 5 t.shapel 'turtle') t.pensize(3) 7 t.pencolor 'green') t.speedte) 9 10 for step in range(108): 21 d = random.randint(50, 100) 12 t.fonard(d) angle = randon.randint(e, 359) t. left (angle) 14 15 16 17 18 19 20 if t.distance(e,e) > 200: t.getole,e) dist = t.distancele,a) print(dist) You are to extend this program so that the turtle change color depending on which region of the window it's in. We will think of the window as having 4 square regions as follows: 1. Upper rights red 2. Upper left: green 3. Lower right: blue 4. Lower left: black The turtle moves around the window as before. When the turtle enters a region, its color should change according to the color assigned to the region (eg. if a turtle enters the upper left region, its color should turn green). To determine which region a turtle is in, your program needs to check the turtle's position using a conditional statement. Obtaining the turtle location can be achieved using the function pos which can be called on a turtle object. For instance, given a turtlet, its x and y coordinates can be retrieved as followsStep 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