-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDie__class.py
40 lines (21 loc) · 862 Bytes
/
Die__class.py
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
"""Create a generic Die class that allows users to pass a list of values that serve as the Die’s sides.
The model is Die class, current_value and possible_values as properties and roll() as the method"""
__author__ = "Ron Shafii"
import random
# notes for my own use
# list_of_random_items = random.sample(group_of_items, num_to_select)
# first_random_item = list_of_random_items[0]
class Die:
""""define the die object"""
def __init__(self, sides):
""" stores the variable passed to sides"""
self.possible_values = sides
self.current_value = None
self.roll()
#self.current_value = random.choice(self.possible_values)
def __str__(self):
"""displays die's value """
return str(self.current_value)
def roll(self):
"""randomly genearate the value of the die """
self.current_value = random.choice(self.possible_values)