Skip to content

Commit b44c0ac

Browse files
authored
Merge pull request #14 from rodukov/new-features
New features
2 parents 44aedf1 + 23fb228 commit b44c0ac

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

main.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import math
22
from os import system
3+
import readline
34

45
# import all components
56
from src.MathFramework import MathFramework
6-
from src.mathframework.Parabola import Parabola
7-
from src.mathframework.quadratic_equation import quadratic_equation
8-
from src.mathframework.progression import progression
7+
# from src.mathframework.Parabola import Parabola
8+
# from src.mathframework.quadratic_equation import quadratic_equation
9+
# from src.mathframework.progression import progression
910

11+
from os import listdir
12+
from os.path import isfile, join
13+
14+
files = [f.replace('.py', '') for f in listdir('src/mathframework') if isfile(join('src/mathframework', f))]
15+
for _import in files:
16+
im = __import__('src.mathframework.'+_import, globals(), locals(), ['*'], 0) # get imported module and import all
17+
func = getattr(im, _import) # find executable class
18+
globals()[_import] = func # save it
1019

1120
def do(_input: str, MF_SCRIPT_ITEMS: list = ['var', 'use', 'run', 'sh']):
1221
_topics = _input.split()
1322
if _topics[0] in MF_SCRIPT_ITEMS:
14-
if (_topics[0] == 'var'): globals()[_topics[1]] = eval(_topics[3])
15-
if (_topics[0] == 'sh'): system(_topics[1])
16-
elif (_topics[0] == 'run'): locals()[_topics[1]]()
17-
else:
23+
if (_topics[0] == 'var'): globals()[_topics[1]] = eval(_topics[3]) # create var
24+
if (_topics[0] == 'sh'): system(_topics[1]) # use bash(system shell)
25+
elif (_topics[0] == 'run'): locals()[_topics[1]]() # run function
26+
else: # call eval()
1827
_result = eval(_input)
1928
print(f'{_input.replace("*", "×").replace("/", "÷").replace("-", "−")} is {_result}')
2029

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import math
22

3-
def quadratic_equation(a: float, b: float, c: float) -> tuple:
3+
def quadratic_equation(a: float = 0, b: float = 0, c: float = 0) -> tuple:
44
D = b**2-4*a*c
55
if (D >= 0): return (-b+math.sqrt(D))/2*a, (-b-math.sqrt(D))/2*a
66
return False

0 commit comments

Comments
 (0)