Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this program, five turtles shaped like balls will randomly move within the window. Start with your previous Turtle Bounce solution and change as follows.
For this program, five turtles shaped like balls will randomly move within the window. Start with your previous Turtle Bounce solution and change as follows.
Write a program called balls_bounce.py.
- Name your file exactly balls_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, Balls Bounce, to your window.
- Create a function to create a turtle object. The function should return a turtle as follows:
- shaped like a circle (ball).
- positioned in the window.
- Colored red.
- pen should be up.
- a random direction, each turtle a new random direction.
- Use a loop to create a list of five balls (turtle objects). In each iteration call the function that creates the ball and then add the ball to a list.
- Use a while True loop to simulate animation.
- Within the while True loop, nest a loop that loops over the items (turtles) in the list
- Move the item (a turtle) forward 5 pixels per movement.
- Use the function written in turtle_bounce that:
- Checks to see if the turtle (ball) has passed the edge of the window.
- If so, moves it backward and changes its direction.
- Repeat for all items in the list
- Add line comments for each logical section of your code.
Upload only your balls_bounce.py to this assignment. A screenshot is not necessary.
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