Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this program, one turtle will randomly move within the window. When it gets to the edge it bounces back onto the window. Write a

For this program, one turtle will randomly move within the window. When it gets to the edge it bounces back onto the window.

Write a program called turtle_bounce.py.

Specifications:

Name your file exactly turtle_bounce.py

Add the standard header: name, date, brief description

Import the turtle and random modules.

Set up a window 500 x 500.

Apply a title, Turtle Bounce, to your window.

Create one turtle object, shaped like a turtle, and position it in the window.

Turtle's pen should be up.

Move the turtle forward, 5 pixels per movement.

Turtle starts in a random direction.

Turtle stays in the same direction until the turtle has passed the edge of the window.

Each time the turtle moves:

Check to see if the turtle has passed the edge of the window.

If the turtle is outside the window, move it back on to the window, approximately where it left. Move it backward (forward -5 pixels).

When the turtle returns to the window, change its direction, to a new random direction.

The program must contain a while loop, one or more if statements, and a function. Use a function for step 11.

Add line comments for each logical section of your code.

Hints: Use one or more of the following expressions, statements, methods, and functions.

SIZE=500

SIZE/2

setup(,)

title()

Turtle(), myTurtle.shape(), myTurtle.penup(), myTurtle.forward(), myTurtle.setheading() where myTurtle is the name of the turtle object variable. You can name the turtle as you please (e.g. john)

while True:

random.randrange(360)

x, y = myTurtle.position()

abs(x)

abs(y)

Save and run your program.

Before it moves it might look like this:

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

What is a job analysis?

Answered: 1 week ago

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago