Skip to content

Commit ceaaa74

Browse files
authored
Merge pull request #122 from ikostan/exercism-sync/7bd9fb414a9ed98f
[Sync Iteration] python/darts/3
2 parents 289de07 + 91edc35 commit ceaaa74

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

solutions/python/darts/3/darts.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

0 commit comments

Comments
 (0)