Skip to content

Commit 3a2ea57

Browse files
committed
Update darts.py
1 parent d7485b3 commit 3a2ea57

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

darts/darts.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Darts is a game where players throw darts at a target."""
22

3+
from math import sqrt
4+
35

46
def score(x: int, y: int) -> int:
57
"""
@@ -16,4 +18,12 @@ 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+
if distance > 10:
24+
return 0
25+
if distance > 5:
26+
return 1
27+
if distance > 1:
28+
return 5
29+
return 10

0 commit comments

Comments
 (0)