Skip to content

Commit f55b3e9

Browse files
committed
contemplate scoring project
1 parent 337769a commit f55b3e9

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

koans/about_scoring_project.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,35 @@
3232
#
3333
# Your goal is to write the score method.
3434

35+
3536
def score(dice):
36-
# You need to write this method
37-
pass
37+
def calculate_points(num, count):
38+
points = 0
39+
if count == 3:
40+
if num == 1:
41+
points = 1000
42+
else:
43+
points = num * 100
44+
elif num == 1:
45+
points = 100 * count
46+
elif num == 5:
47+
points = 50 * count
48+
return points
49+
50+
counts = {}
51+
52+
for num in dice:
53+
counts[num] = counts.get(num, 0) + 1
54+
55+
total = 0
56+
for k, v in counts.items():
57+
if v >= 3:
58+
total += calculate_points(k, 3)
59+
total += calculate_points(k, v - 3)
60+
else:
61+
total += calculate_points(k, v)
62+
return total
63+
3864

3965
class AboutScoringProject(Koan):
4066
def test_score_of_an_empty_list_is_zero(self):

0 commit comments

Comments
 (0)