Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Directions

Modify the program in the following ways:

  1. Write appropriate comments for this program and function. Include:
    1. A header comment for the program
    2. A header for the function describing the parameters and return value.
    3. Comment the blocks of code. The text has descriptions of all this, so reread that if necessary.
  2. Create 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. Have both turtles move randomly, but independently, so you will have to flip a coin for each turtle.
  3. Modify the while loop so that the program stops when either turtle leaves the screen. This is pretty easy, once you see it.
  4. 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).
  5. Write a Boolean function that has two turtles as parameters, and returns True if the turtles are at exactly the same location, and False otherwise.
  6. 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. This is very much like step 3.
  7. 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 ???

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

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago