Question: Please use Python language and provide comments on how you write the code Your friend, turtle, wants to run off and marry his princess girlfriend
Please use Python language and provide comments on how you write the code
Your friend, turtle, wants to run off and marry his princess girlfriend but an all-powerful otaku opposes his plan. He hires two brothers, a pair of plumbers, to thwart turtle's plan and kidnap the princess.
Your turtle friend asks you to create a program, turtle_friend.py, to devise a means to evade the plumbers and escape with his princess to live happily ever after.
Task 1
Create a function to help turtle determine how much to carry in his shell while on the run. Though he may not be "teenage-ninja" strong, turtle is still "mutant" strong since he can carry up to 100 pounds.
Start by defining a list of supplies; your list should contain at least six item names. Also, either in a separate list or as part of the supplies list, define a unique weight for each supply item in the supplies list.
Your function should repeatedly print the supply list and prompt the user to select an item from the list. Add that selected item to a 'carry' list in order to keep track of which items turtle has selected. Then subtract the selected items weight from your friends maximum capacity so that after each selection, the function can display how much more weight the turtle can carry. Keep prompting and subtracting until turtle's remaining capacity is less than the weight of the lightest item in the list. At that time, your function should display a message to let your turtle friend know that he cannot carry any more items. It should then display a list of all the supplies that have been selected.
Notes:
The output should look like a variation of this (where the menu contains supplies and weights that you define):
Remaining capacity: 100 pounds
1 food mushrooms, 10 pounds
2 food speed-enhancing star snacks, 15 pounds
3 food wildflowers, 20 pounds
4 clothing fireball-proof vest, 30 pounds
5 clothing crush-proof shell plating, 40 pounds
6 ammo fireballs, 50 pounds
Select an item:
Remaining capacity: 70 pounds (if user selects 4)
1 food mushrooms, 10 pounds
2 food speed-enhancing star snacks, 15 pounds
3 food wildflowers, 20 pounds
4 clothing fireball-proof vest, 30 pounds
5 clothing crush-proof shell plating, 40 pounds
6 ammo fireballs, 50 pounds
Select an item:
Remaining capacity: 20 pounds (if user selects 6)
1 food mushrooms, 10 pounds
2 food speed-enhancing star snacks, 15 pounds
3 food wildflowers, 20 pounds
4 clothing fireball-proof vest, 30 pounds
5 clothing crush-proof shell plating, 40 pounds
6 ammo fireballs, 50 pounds
Select an item:
Remaining capacity: 5 pounds (if user selects 2)
Cannot carry any more items.
Shell contents:
clothing fireball-proof vest
ammo fireballs
food speed-enhancing star snacks
Tips:
For the supply list, you should use either
a list that contains a [name, weight] sublist for each supply item
parallel lists (one list of supply names & a corresponding list for supply weights)
A for-loop can be used to print the supply list.
An accumulator pattern can subtract from your friends carrying capacity.
If/else statements can determine if your friends remaining capacity is enough for another selection.
A while-loop would keep the program running until your friends capacity is too low.
Task 2
Create a function that uses Turtle Graphics to simulate your turtle friends escape. The function should define a parameter, num_enemies, to represent the number of enemies your friend could face. Enemies will be displayed as red or green bouncing balls.
Create num_enemies red or green bouncing balls, each located at a random location but no closer than a ball's width from any window borders. For each ball, select a random direction (dx and dy) for each ball to move in the combined range of (-5, 5), excluding 0.
Note: Do NOT have all balls use the same dx and dy values; rather, each ball should have its own dx and dy. You will need to use parallel lists (where a ball's dx and dy are located at the same index in both lists) or a list of sublists to manage the ball's dx and dy movements.
Create a turtle (your turtle friend) in the lower right-hand corner of the window. The turtle should be the same size as the balls. Use the arrow keys to control your turtle friends movement. When running your function, the user will use the arrow keys to try to move your turtle friend from the starting corner of the window to the OPPOSITE corner without letting the turtle be hit by a ball.
You will need to detect collisions between each ball and the window boundaries in order to know whether to reverse the ball's heading. You do NOT need to detect collisions with the boundaries of the window for your turtle friend. Also, the balls do NOT need to collide with each other; that is, they may pass through each other and/or overlap.
If your friend collides with a bouncing ball, he is captured (ie. game over). If your friend eludes the bouncing balls, then he escapes (ie. your friend wins). For each ending condition, print a message of your choosing (eg "Your friend made it!" or "Your friend is now turtle soup!") to indicate the result.
Notes:
Set the window to 500 pixels x 500 pixels.
Both your turtle friend and the enemies are defined as turtle objects; use a turtle shape for your friend and circle shape for the enemies.
Set the size of your friend and the enemies to turtlesize 3; this value can vary slightly but your friend and the enemies should be the SAME size.
To test for a collision between your turtle friend and an enemy, you'll want to determine when the distance between them is small enough to know they are right beside each other. You can use a turtle object's .distance() method to determine distance between to turtle objects. The following statement returns the distance between turtle1 and turtle2:
turtle1.distance(turtle2)
Additional Assignment Criteria
Place all functions in the same Python file, turtle_friend.py.
Include a header with the filename, brief descriptions of each function, your name and a date.
Add line comments before each function and at other appropriate sections of your code.
Keep your functions are reasonable size by breaking their contents into additional functions that are called from your function (keeps your code modular).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
