forked from china-testing/python-api-tesing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.py
More file actions
executable file
·38 lines (27 loc) · 695 Bytes
/
dice.py
File metadata and controls
executable file
·38 lines (27 loc) · 695 Bytes
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
# dice.py
from random import randint
class Dice:
def __init__(self, n):
self.dice = [Die() for _ in range(n)]
def rollall(self):
for die in self.dice:
die.roll()
def values(self):
return [int(die) for die in self.dice]
def __str__(self):
return str(self.values())
class Die:
def __init__(self):
self.value = randint(1, 6)
def roll(self):
self.value = randint(1, 6)
def __str__(self):
return str(self.value)
def __int__(self):
return self.value
def main():
dice = Dice(5)
dice.rollall()
print(dice)
if __name__ == "__main__":
main()