Archery Scoring Algorithm

archeryIn 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.

Scoring System


For our program we will be using the following scoring system:
archery-target

Pythagoras’ Theorem


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).

archery-pythagoras

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).

Extension Task


Can you let the computer shoot three arrows and display the total score of all three arrows, by adding the score of each arrow.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 11

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , ,