File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 1010
1111import random
1212class Die (object ):
13- def __init__ (self , sides ):
14- self .sides = sides
13+ #A dice has a feature of number about how many sides it has when it's established,like 6.
14+ def __init__ (self ):
15+ self .sides = 6
16+
17+ """because a dice contains at least 4 planes.
18+ So use this method to give it a judgement when you need to change the instance attributes."""
19+ def set_sides (self ,sides_change ):
20+ if self .sides_change >= 4 :
21+ self .sides = self .sides_change
22+ print ("change sides!" )
23+ else :
24+ print ("wrong sides!" )
25+
1526 def roll (self ):
1627 return random .randint (1 , self .sides )
1728
18- d = Die (6 )
19- d1 = Die (6 )
29+ d = Die ()
30+ d1 = Die ()
31+ d .set_sides (4 )
32+ d1 .set_sides (4 )
2033print (d .roll (), d1 .roll ())
You can’t perform that action at this time.
0 commit comments