Question: Directions Modify the program in the following ways: Write appropriate comments for this program and function. Include: A header comment for the program A header

Directions

Modify the program in the following ways:

  1. Write appropriate comments for this program and function. Include:
  2. A header comment for the program
  3. A header for the function describing the parameters and return value.
  4. Comment the blocks of code.
  5. The text has descriptions of all this, so reread that if necessary.
  6. Following the process in the previous unit's assignment, write function to randomly move a turtle. The function should have at least one parameter, the turtle to move. Call this function in your main program instead of the code that is already there. If you do this correctly, your program will behave the same.
  7. Create a second turtle, make it a different color, and start it at a different location than the current one. The location should be 100 units away, either horizontally or vertically.
  8. The second turtle should move randomly 5 times for every time the first turtle does. It should also move 1/5 the distance as the original turtle each time. This is where having a function with proper parameters comes in handy.
  9. After the loop, write a message, in the center of the window, indicating which turtle was higher up. Use the turtle that is higher (more toward the top of the screen) to do the writing. Be sure your message specifies the turtle. See the write() function in the turtle module for writing text messages in the window.
  10. Once your program works the way you want, rewrite the if statement in the function isInScreen, so it still implements the same logic, but does it a different way. For example, maybe you can use an elif, or maybe you can write several statements and eliminate the use of or. You should probably do this step last, or else if you make a mistake, you'll never be able to debug the rest of your 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()

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!