1
1
# Script Name : dice.py
2
2
# Author : Craig Richards
3
3
# Created : 05th February 2017
4
- # Last Modified :
4
+ # Last Modified :
5
5
# Version : 1.0
6
6
7
7
# Modifications :
8
8
9
- # Description : This will randomly select two numbers, like throwing dice,
10
- # you can change the sides of the dice if you wish
9
+ # Description : This will randomly select two numbers,
10
+ # like throwing dice, you can change the sides of the dice if you wish
11
11
12
12
import random
13
13
14
14
15
15
class Die (object ):
16
- # A dice has a feature of number about how many sides it has when it's established,like 6.
16
+ # A dice has a feature of number about how many sides it has when it's
17
+ # established,like 6.
17
18
def __init__ (self ):
18
19
self .sides = 6
19
20
20
21
"""because a dice contains at least 4 planes.
21
- So use this method to give it a judgement when you need to change the instance attributes."""
22
+ So use this method to give it a judgement when you need
23
+ to change the instance attributes.
24
+ """
22
25
def set_sides (self , sides_change ):
23
26
if sides_change >= 4 :
24
27
if sides_change != 6 :
25
28
print ("change sides from 6 to " , sides_change , " !" )
26
- else : # added else clause for printing a message that sides set to 6
27
- print ("sides set to 6" )
29
+ else :
30
+ # added else clause for printing a message that sides set to 6
31
+ print ("sides set to 6" )
28
32
self .sides = sides_change
29
33
else :
30
34
print ("wrong sides! sides set to 6" )
@@ -37,4 +41,4 @@ def roll(self):
37
41
d1 = Die ()
38
42
d .set_sides (4 )
39
43
d1 .set_sides (4 )
40
- print (d .roll (), d1 .roll ())
44
+ print (d .roll (), d1 .roll ())
0 commit comments