-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedMath.py
More file actions
70 lines (58 loc) · 2.03 KB
/
AdvancedMath.py
File metadata and controls
70 lines (58 loc) · 2.03 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import random
import time
from math import sqrt
from Hal.Classes import Response
from Hal.Decorators import reg
from Hal.Skill import Skill
from Hal import initialize_assistant
assistant = initialize_assistant()
class AdvancedMath(Skill):
def __init__(self):
self.my_num = 0
@reg(name="Exponent")
def exponent(self, base, exp):
"""
Calculate the exponentiation of base raised to the power of exp.
:param integer base: The base number.
:param integer exp: The exponent number.
:return: The response object with the calculated power.
:rtype: Response
"""
base = int(base)
exp = int(exp)
power = base
for i in range(1, exp):
power = assistant.call_function("simplemath-multiply", (power, base)).data
return Response(succeeded=True, data=power)
@reg(name="Square Root")
def square_root(self, base):
"""
Calculate the square root of a given number.
:param integer base: The number to calculate the square root of.
:return: The response object with the calculated square root.
:rtype: Response
"""
base = int(base)
return Response(succeeded=True, data=sqrt(base))
@reg(name="Get My Number")
def get_my_num(self):
"""
Get the value of the 'my_num' attribute.
:return: The response object with the current value of 'my_num'.
:rtype: Response
"""
return Response(succeeded=True, data=self.my_num)
@reg(name="Get Number")
def get_num(self, thing=None):
"""
Get the 'my_number' value and increment 'my_num' attribute.
:param thing: Placeholder argument.
:return: The response object with the current value of 'my_number'.
:rtype: Response
"""
num = self.get("my_number")
if self.my_num:
self.my_num += 1
else:
self.my_num = 222
return Response(succeeded=True, data=num)