File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change 32
32
#
33
33
# Your goal is to write the score method.
34
34
35
+
35
36
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
+
38
64
39
65
class AboutScoringProject (Koan ):
40
66
def test_score_of_an_empty_list_is_zero (self ):
You can’t perform that action at this time.
0 commit comments