-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator_actions.py
38 lines (32 loc) · 1.31 KB
/
calculator_actions.py
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
import re
import math
import sympy as sy
from sympy import *
from sympy.interactive import init_printing
init_printing(pretty_print=True)
def calculate(equation: str) -> str:
print("Equação: ", equation)
x, y, z = sy.symbols('x y z')
if 'Limit x->' in equation:
f = Lambda(x, equation[14:-1])
print("equation[9:11]: ", equation[9:11])
print("str(equation[11]): ", str(equation[11]))
successfully_solved_equation = limit(f(x), x, equation[9:11], str(equation[11]))
if 'Derivar' in equation:
if "f'(" in equation:
f = Lambda(x, equation[16:-1])
f1 = Lambda(x, diff(f(x),x))
successfully_solved_equation = f1(int(equation[11:12]))
elif "f(" in equation:
f = Lambda(x, equation[15:-1])
successfully_solved_equation = sy.diff(f(x), x)
if 'Integrar' in equation:
if "f(x) (" in equation:
f = Lambda(x, equation[25:-1])
print("f: ", f)
successfully_solved_equation = integrate(f(x), (x, equation[15:17], equation[18:20]))
elif "f(x) =" in equation:
f = Lambda(x, equation[16:-1])
successfully_solved_equation = integrate(f(x), x)
print("Resultado: ", successfully_solved_equation)
return str(successfully_solved_equation)