-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (56 loc) · 1.56 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import os
import argparse
import lib.parser as parser
import lib.calc as calc
import lib.solver as solver
import lib.formatter as form
import mpmath
mpmath.mp.prec = 3333
mpmath.mp.dps = 1000
# expression = "5*x^3-4*x^2+1*x-10"
# parsed_expression = lib.parser.parse(expression)
# lib.solver.solve(parsed_expression)
sys.stdout.write("This is the polynomial solver for the Algebra 2 Honors class.")
pars = argparse.ArgumentParser()
pars.add_argument(
"-v",
"--verbose",
help="increase output verbosity",
required=False,
action="store_true",
default=False,
)
pars.add_argument(
"-a",
"--app",
help="activate server for application",
required=False,
action="store_true",
default=False
)
args = pars.parse_args()
if(args.app):
exit(os.system("python3 app.py"))
target = input("Please enter your expression/equasion to solve: ")
# eqtype=solver.find_type(parsedexpr)
if(os.path.isfile(target)):
import recognization as recognition
from PIL import Image
expression = recognition.recognize(target)
sys.stdout.write("recognized: "+str(expression)+"\n")
else:
expression=target
if "/" in expression or "\\" in expression:
raise ValueError("File does not exist: " + expression)
if "=" in expression:
expression=expression[expression.find("=")+1:]
parsedexpr = parser.parse(expression)
if(args.verbose):
sys.stdout.write(str(parsedexpr)+"\n")
solution = solver.solve(parsedexpr)
sys.stdout.write(
"Solutions are: \n\t"
+ ", \n\t".join(list(set(form.formatter(i) for i in solution)))
+ "\n"
)