Skip to main content

Simple tool for calculate the numerical result from a expression string by python

Project description

Python Opcalc 0.0.1

Simple tool for calculate the numerical result from a expression string by python This code mainly focused on the principle of expression calculation by using stack (one of the basic data structure) You can use eval() function in python as well!

Install

Just use pip to install ! :D

pip install opcalc

License

MIT License

Examples

Simple calculator program:

import opcalc.core as opc
calculator = opc.OperationCalculator()
calculator.input_str = "#*60"
print(calculator.CalcExpression())
print("SymCalc demo")
#print("Copyright (c) Quix Fan  @ZQWEI  All right reserved.")
calculator.input_str = "#*60"
print(calculator.CalcExpression())
while True:
    try:
        result = calculator.CalcExpression()
        print(result)
    except:
        print("Invalid Input!")
    calculator.input_str = "#*60"
    print(calculator.CalcExpression())

Customized string for calculation

import opcalc.core as opc
calculator = opc.OperationCalculator()
calculator.input_str = "2^3+(9/2^2)^2+1.5^0.3+9"
result=calculator.CalcExpression()
print(result)

The result should be 23.191846935456855

Comparisom

test code:

import opcalc.core as opc
calculator = opc.OperationCalculator()
from time import time
start_time=time()
len=10000

for i in range(len):
    calculator.input_str = "2^3+(9/2^2)^2^2+1.5^0.3+9"
    result=calculator.CalcExpression()
print("Opcalc Time:" +str(time()-start_time))
start_time=time()
for i in range(len):
    input_str = "2^3+(9/2^2)^2^2+1.5^0.3+9"
    input_str=input_str.replace("^","**")
    eval(input_str)
print("eval Time:"+str(time()-start_time))

result: Opcalc Time:0.7659511566162109 eval Time:0.17852163314819336

Although it is slower,but the principle of using stack remain the same, you can rewrite it into other languages easily!

Releases

Lastest version: opcalc==0.0.1a3

pip install opcalc==0.0.1a3

1.faster calculation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opcalc-0.0.1a3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opcalc-0.0.1a3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file opcalc-0.0.1a3.tar.gz.

File metadata

  • Download URL: opcalc-0.0.1a3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for opcalc-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 0f047b7e104cd225f3c673a4c19ca7d904c9fb8ade42bee6a21c2eae07fcefa1
MD5 7f3fc19f9fbf20e9dcc055672beac088
BLAKE2b-256 604cde3f7429a9cc9e983565d07ec9053c1937326f79aab8e7fd8daf6729d2cd

See more details on using hashes here.

File details

Details for the file opcalc-0.0.1a3-py3-none-any.whl.

File metadata

  • Download URL: opcalc-0.0.1a3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for opcalc-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 959e843a7494604dcc174076385b80807f60f41fdb8cfe3cc20aeadd8e102423
MD5 91226279c562a0b5354002a3a9044a4e
BLAKE2b-256 a39bdb90bb5fd913a27dc4f06e60656100da1a5d16ee241f82f838e5110c7073

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page