Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this python code : import random import turtle def isInScreen(win,turt): leftBound = -win.window_width() / 2 rightBound = win.window_width() / 2 topBound = win.window_height() /

Using this python code :

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()

I'm asked to make a second turtle and start it at a different location than the current one. The location should be 50 units away, either horizontally or vertically, which i figured out, but i don't know how to Have both turtles move randomly, but independently, so you will have to flip a coin for each turtle.

I also have to modify the while loop so that the program stops when either turtle leaves the screen. This is pretty easy, once you see it. and after the loop, print a message indicating which turtle won. You decide whether it was the one still in the screen or the one that left. Use the turtle that left the screen to write the message (see the write() function in the turtle module). Making a Boolean function that has two turtles as parameters, and returns True if the turtles are at exactly the same location, and False otherwise and then Call your Boolean function from Step 5 to also stop the program when the two turtles end up at the same location. In this case, print there was no winner.

Add another feature to your program. Some ideas are a) a fancier ending message, b) a third turtle, c) more randomness, like letting a random turtle go first each time or having a turtle randomly skip a turn, or jQuery22409972527017888047_1568358365211?

This doesn't have to be too fancy, but should be more than just adding one line of code.

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

Students also viewed these Programming questions