Question: 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 pythonIn python Exercise 1 (5 points) Consider the program we developed in

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 follows

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!