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

# 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
``````

## 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

This version 0.0.1a3 pre-release 0.0.1a2 pre-release 0.0.1a0 pre-release

Uploaded `source`
Uploaded `py3`
{"ft_lang_label":"__label__en","ft_lang_prob":0.50575703,"math_prob":0.99872804,"size":2095,"snap":"2022-27-2022-33","text_gpt3_token_len":543,"char_repetition_ratio":0.17264467,"word_repetition_ratio":0.1319149,"special_character_ratio":0.2763723,"punctuation_ratio":0.15733333,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.998993,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-01T02:59:02Z\",\"WARC-Record-ID\":\"<urn:uuid:b0779d88-6a3d-42a0-b53d-a8862532c474>\",\"Content-Length\":\"55495\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f7f062fd-b115-4511-ae43-6c19eee92703>\",\"WARC-Concurrent-To\":\"<urn:uuid:92d3b1d6-1e30-441b-a0b7-725874c14f82>\",\"WARC-IP-Address\":\"151.101.192.223\",\"WARC-Target-URI\":\"https://pypi.org/project/opcalc/\",\"WARC-Payload-Digest\":\"sha1:GMNSAQW4M4K5WTSVA7IOCWK63CWAYAEG\",\"WARC-Block-Digest\":\"sha1:EBMRHP3UN4BIE6M7BCQQCXYX3SOOZ27M\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103917192.48_warc_CC-MAIN-20220701004112-20220701034112-00380.warc.gz\"}"}