@@ -23,36 +23,37 @@ def maclaurin_sin(theta: float, accuracy: int = 30) -> float:
23
23
>>> maclaurin_sin("10")
24
24
Traceback (most recent call last):
25
25
...
26
- ValueError: maclaurin_sin() requires int/float for theta and +ive int for accuracy
26
+ ValueError: maclaurin_sin() requires a int or float for theta
27
27
>>> maclaurin_sin(10, -30)
28
28
Traceback (most recent call last):
29
29
...
30
- ValueError: maclaurin_sin() requires int/float for theta and +ive int for accuracy
30
+ ValueError: maclaurin_sin() requires a positive int for accuracy
31
31
>>> maclaurin_sin(10, 30.5)
32
32
Traceback (most recent call last):
33
33
...
34
- ValueError: maclaurin_sin() requires int/float for theta and +ive int for accuracy
34
+ ValueError: maclaurin_sin() requires a positive int for accuracy
35
35
>>> maclaurin_sin(10, "30")
36
36
Traceback (most recent call last):
37
37
...
38
- ValueError: maclaurin_sin() requires int/float for theta and +ive int for accuracy
38
+ ValueError: maclaurin_sin() requires a positive int for accuracy
39
39
"""
40
40
41
- if (
42
- not isinstance (accuracy , int )
43
- or accuracy <= 0
44
- or not isinstance (theta , (int , float ))
45
- ):
41
+ if not isinstance (theta , (int , float )):
46
42
raise ValueError (
47
- "maclaurin_sin() requires int/float for theta and +ive int for accuracy"
43
+ "maclaurin_sin() requires a int or float for theta"
44
+ )
45
+
46
+ if not isinstance (accuracy , int ) or accuracy <= 0 :
47
+ raise ValueError (
48
+ "maclaurin_sin() requires a positive int for accuracy"
48
49
)
49
50
50
51
theta = float (theta )
51
52
52
- _total = 0
53
+ total = 0
53
54
for r in range (accuracy ):
54
- _total += ((- 1 ) ** r ) * ((theta ** (2 * r + 1 )) / (factorial (2 * r + 1 )))
55
- return float (_total )
55
+ total += ((- 1 ) ** r ) * ((theta ** (2 * r + 1 )) / (factorial (2 * r + 1 )))
56
+ return float (total )
56
57
57
58
58
59
if __name__ == "__main__" :
0 commit comments