diff --git a/calc/calc.py b/calc/calc.py index 907d095..1fea477 100644 --- a/calc/calc.py +++ b/calc/calc.py @@ -127,7 +127,11 @@ def eval_number(parse_result): e.g. [ '7.13', 'e', '3' ] -> 7130 Calls super_float above. """ - return super_float("".join(parse_result)) + for item in parse_result: + if "." in item or "e" in item or "E" in item: + return super_float("".join(parse_result)) + + return int("".join(parse_result)) def eval_atom(parse_result): @@ -185,7 +189,7 @@ def eval_sum(parse_result): Allow a leading + or -. """ - total = 0.0 + total = 0 current_op = operator.add for token in parse_result: if token == '+': @@ -203,7 +207,7 @@ def eval_product(parse_result): [ 1, '*', 2, '/', 3 ] -> 0.66 """ - prod = 1.0 + prod = 1 current_op = operator.mul for token in parse_result: if token == '*': @@ -265,11 +269,6 @@ def eval_variable(x): return all_variables[casify(x[0])] def eval_function(x): - # This condition here is only for factorial function - if isinstance(x[1], numbers.Real): - if math.ceil(x[1]) == x[1]: - return all_functions[casify(x[0])](int(x[1])) - return all_functions[casify(x[0])](x[1]) evaluate_actions = { diff --git a/tox.ini b/tox.ini index 88b4afa..3d77849 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,11 @@ [tox] -envlist = py{38, 311}quality +envlist = py{38,311},quality [testenv] allowlist_externals = touch deps = + setuptools -r requirements/test.txt commands = coverage run setup.py test @@ -12,6 +13,7 @@ commands = [testenv:quality] deps = + setuptools -r requirements/test.txt commands = pycodestyle calc symmath tests