File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 11"""Darts is a game where players throw darts at a target."""
22
3+ from math import sqrt
4+
35
46def score (x : int , y : int ) -> int :
57 """
@@ -16,4 +18,16 @@ def score(x: int, y: int) -> int:
1618 :param y: The y-coordinate where the dart landed
1719 :return: The points scored (0, 1, 5, or 10)
1820 """
19- pass
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
Original file line number Diff line number Diff line change 1- # pylint: disable=C0301
1+ # pylint: disable=C0114, C0115, C0116, R0904
22
33# These tests are auto-generated with test data from:
44# https://github.com/exercism/problem-specifications/tree/main/exercises/darts/canonical-data.json
Original file line number Diff line number Diff line change 1+ """Darts is a game where players throw darts at a target."""
2+
3+
4+ def score (x : int , y : int ) -> int :
5+ """
6+ Calculate the points scored in a single toss of a Darts game.
7+
8+ Given the x and y coordinates where a dart lands, returns the score
9+ based on the distance from the center (0, 0):
10+ - Inner circle (distance <= 1): 10 points
11+ - Middle circle (distance <= 5): 5 points
12+ - Outer circle (distance <= 10): 1 point
13+ - Outside target (distance > 10): 0 points
14+
15+ :param x: The x-coordinate where the dart landed
16+ :param y: The y-coordinate where the dart landed
17+ :return: The points scored (0, 1, 5, or 10)
18+ """
19+ pass
You can’t perform that action at this time.
0 commit comments