Skip to content

Commit

Permalink
Merge pull request #14 from rodukov/new-features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
rodukov committed Sep 22, 2022
2 parents 44aedf1 + 23fb228 commit b44c0ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import math
from os import system
import readline

# import all components
from src.MathFramework import MathFramework
from src.mathframework.Parabola import Parabola
from src.mathframework.quadratic_equation import quadratic_equation
from src.mathframework.progression import progression
# from src.mathframework.Parabola import Parabola
# from src.mathframework.quadratic_equation import quadratic_equation
# from src.mathframework.progression import progression

from os import listdir
from os.path import isfile, join

files = [f.replace('.py', '') for f in listdir('src/mathframework') if isfile(join('src/mathframework', f))]
for _import in files:
im = __import__('src.mathframework.'+_import, globals(), locals(), ['*'], 0) # get imported module and import all
func = getattr(im, _import) # find executable class
globals()[_import] = func # save it

def do(_input: str, MF_SCRIPT_ITEMS: list = ['var', 'use', 'run', 'sh']):
_topics = _input.split()
if _topics[0] in MF_SCRIPT_ITEMS:
if (_topics[0] == 'var'): globals()[_topics[1]] = eval(_topics[3])
if (_topics[0] == 'sh'): system(_topics[1])
elif (_topics[0] == 'run'): locals()[_topics[1]]()
else:
if (_topics[0] == 'var'): globals()[_topics[1]] = eval(_topics[3]) # create var
if (_topics[0] == 'sh'): system(_topics[1]) # use bash(system shell)
elif (_topics[0] == 'run'): locals()[_topics[1]]() # run function
else: # call eval()
_result = eval(_input)
print(f'{_input.replace("*", "×").replace("/", "÷").replace("-", "−")} is {_result}')

Expand Down
2 changes: 1 addition & 1 deletion src/mathframework/quadratic_equation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math

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

0 comments on commit b44c0ac

Please sign in to comment.