File tree Expand file tree Collapse file tree 1 file changed +19
-14
lines changed Expand file tree Collapse file tree 1 file changed +19
-14
lines changed Original file line number Diff line number Diff line change 44
55class ChaosGame :
66 def __init__ (self , n : int = 3 , r : float = 0.5 ):
7- """Need to make sure input is of right type, and 0 < r > 1, n > 2.
7+ """Need to make sure input is of right type, and 0 < r < 1, n > 2.
88 This checks first, then sets the attributes after. sets to default if not possible. """
99 try :
1010 if not isinstance (n , int ):
11- raise TypeError ("n should be an int > 2 " )
11+ raise TypeError ("n should be an int" )
1212 except TypeError as terr :
1313 print (terr .args )
1414 print ("trying to convert" )
1515 n = int (n )
16- if n < - 2 :
17- self .n = self .n * - 1
18- elif - 2 <= n <= 2 :
19- print ("using default n, 3" )
20- self .n = 3
16+ if n < - 2 :
17+ print ("n need to be int > 2, converting to positive int" )
18+ self .n = self .n * - 1
19+ elif - 2 <= n <= 2 :
20+ print ("using default n = 3" )
21+ self .n = 3
22+ else :
23+ self .n = n
24+
2125 try :
22- if not isinstance (n , float ):
23- raise TypeError ("r should be an float 0 < r > 1" )
26+ if not isinstance (r , float ):
27+ raise TypeError ("r should be a float 0 < r < 1" )
2428 except TypeError as terr :
2529 print (terr .args )
2630 print ("trying to convert" )
2731 r = float (r )
28- if not (0 < r > 1 ):
29- print ("using default, 0.5" )
30- self .r = 0.5
31- else :
32- self .r = r
32+ if not (0 < r < 1 ):
33+ print ("using default = 0.5" )
34+ self .r = 0.5
35+ else :
36+ self .r = r
37+
3338
3439game = ChaosGame ()
You can’t perform that action at this time.
0 commit comments