Question
import random import turtle def isInScreen(win,turt): leftBound = -win.window_width() / 2 rightBound = win.window_width() / 2 topBound = win.window_height() / 2 bottomBound = -win.window_height() /
import random
import turtle
def isInScreen(win,turt):
leftBound = -win.window_width() / 2
rightBound = win.window_width() / 2
topBound = win.window_height() / 2
bottomBound = -win.window_height() / 2
turtleX = turt.xcor()
turtleY = turt.ycor()
stillIn = True
if turtleX > rightBound or turtleX < leftBound:
stillIn = False
if turtleY > topBound or turtleY < bottomBound:
stillIn = False
return stillIn
def main():
wn = turtle.Screen()
# Define your turtles here
june = turtle.Turtle()
june.shape('turtle')
while isInScreen(wn,june):
coin = random.randrange(0, 2)
if coin == 0:
june.left(90)
else:
june.right(90)
june.forward(50)
wn.exitonclick()
main()
Modify the program in the following ways:
A header comment for the program
A header for the function describing the parameters and return value.
Comment the blocks of code.
Make a new turtle, a black hole turtle, that moves to some random location on the screen and draws a black dot of diameter 100. Use the .dot function instead of .circle, since you want the turtle at the center of the figure.
Make a boolean function that has two turtles as parameters, and returns true if the turtles are within 50 units of each other and false otherwise.
Modify the while loop so that the program stops when the turtle leaves the screen or when it touches the black hole.
Modify the body of the while loop so that if the turtle wanders off the screen either to the right or the left, it reappears on the opposite side of the screen.
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