File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ """Darts is a game where players throw darts at a target."""
2+
3+ from math import sqrt
4+
5+
6+ def score (x : float , y : float ) -> int :
7+ """
8+ Calculate the points scored in a single toss of a Darts game.
9+
10+ Given the x and y coordinates where a dart lands, returns the score
11+ based on the distance from the center (0, 0):
12+ - Inner circle (distance <= 1): 10 points
13+ - Middle circle (distance <= 5): 5 points
14+ - Outer circle (distance <= 10): 1 point
15+ - Outside target (distance > 10): 0 points
16+
17+ :param x: The x-coordinate where the dart landed
18+ :param y: The y-coordinate where the dart landed
19+ :return: The points scored (0, 1, 5, or 10)
20+ """
21+ # Calculate distance form the center of the circle (0, 0)
22+ distance : float = sqrt (pow (x , 2 ) + pow (y , 2 ))
23+ # Outside target
24+ if distance > 10 :
25+ return 0
26+ # Outer circle
27+ if distance > 5 :
28+ return 1
29+ # Middle circle
30+ if distance > 1 :
31+ return 5
32+ # Inner circle
33+ return 10
You can’t perform that action at this time.
0 commit comments