In this challenge we will write a Python program to randomly shoot an arrow on a target. We will then use Pythagoras’ Theorem to calculate the distance between the arrow impact and the centre of the target. This distance will let us find out how many points to award to this shoot.
For our program we will be using the following scoring system:
The arrow will be issued (x,y) coordinates randomly. Our script will use these coordinates to calculate the distance of the arrow from the centre of the target (0,0).
With this distance we can then decide how many points to be given using the following criteria:
- Distance between 0 – 30 pixels (Yellow Ring) = 10 points
- Distance between 31 – 60 pixels (Red Ring) = 5 points
- Distance between 61 – 90 pixels (Blue Ring) = 3 points
- Distance between 91 – 120 pixels (Black Ring) = 2 points
- Distance between 121 – 150 pixels (White Ring) = 1 point
- Distance above 150 pixels (Off Target) = 0 point
The code so far…
As you can see we have started the code for you below but still have work to do on line 44 to 54 to calculate the distance of the arrow from the centre of the target and calculate the score.
You challenge is to complete this code (line 44 to 54).
Can you let the computer shoot three arrows and display the total score of all three arrows, by adding the score of each arrow.
Solution...The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area