-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw04.py
More file actions
48 lines (35 loc) · 1.03 KB
/
Copy pathhw04.py
File metadata and controls
48 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import random
class Die:
def __init__(self):
self.__face = random.randrange(1, 7)
def roll(self) -> None:
self.__face = random.randrange(1, 7)
@property
def face(self):
return self.__face
class YahtzeeDice:
def __init__(self):
self.__dice = [Die() for _ in range(5)]
def roll_dices(self, dice_indices:int) -> int:
for index in dice_indices:
self.__dice[index].roll()
def show_faces(self):
for die in self.__dice:
print(die.face, end=' ')
print()
def get_faces(self):
return [die.face for die in self.__dice]
def count_faces(self, value:int) -> int:
count = 0
for die in self.__dice:
if die.face == value:
count += 1
return count
def sum_faces(self) -> int:
total = 0
for die in self.__dice:
total += die.face
return total
if __name__ == '__main__':
dices = YahtzeeDice()
dices.show_faces() # 주사위 눈 출력