Skip to main content

A simple calcaultor for daily usage

Project description

A Simple Calculator

Based on decimal.Decimal.

Decimal “is based on a floating-point model which was designed with people in mind, and necessarily has a paramount guiding principle – computers must provide an arithmetic that works in the same way as the arithmetic that people learn at school.” – excerpt from the decimal arithmetic specification

How to use

install

pip install dailycalc

import into your code

from dailycalc import calculate

print(calculate("sum(123+3)"))

once-off calculate

python -m dailycalc "sum(0.1, 0.2)"

iteractive mode

python -m dailycalc -i

Operators & Functions

currently supporting:

"+ - * / ^"

"sum max min abs round hex oct"

Interactive mode

Every result is stored in register from [a-z] cyclically, that is when reaching the last one "z", the register would go back to "a" and cover the old value.

"@a" gives the value in "a". "@@" gives the previous result.'

for example:

>>> 1
>>> @a: 1
>>> @a + 2
>>> @b: 3
>>> ...
>>> @z: 351
>>> @z + 1
>>> @a: 352
>>> @@- 1
>>> @b: 351

Support HEX, OCT, Scientific input

  1. HEX: "0x12E", "0X12E" only support integar
  2. OCT: "0o123", "0O123" only support integar
  3. Scientific: "-123.12E-123" or "-123.12e+123"

Support terminal highlight in -i

Error message with highlight


>>> abs(sum(1,2,3),11)
>>> Input: abs(sum(1,2,3),11)
           ---------------^^-----
    Error: func abs: expecting 1 parameters got 2
>>>
>>> sum(1,
>>> Input: sum(1,
           ------^---
    Error: expecting Number
>>>

reference for interactive mode


--- Modes ---
STAY mode (prompt:"===") (Default)
save result by call "save" command
WALKING mode (prompt:">>>")
automatically save results and move to next register
--- Commands ---
"exit" exit program.
"show" show all results in register.
"reset" clear all results in register.
"stay" switch to STAY mode.
"go" save result & switch to WALKING mode.
"save [tag]" save result (in STAY Mode).
--- Functions ---
sum(1, 2, 2+1) => 6
max(1, sum(2, 1)) => 3
min(1, 2) => 1
abs(1-12) => 11
round(12.16, 1) => 12.2
hex(10) => 0xa
oct(10) => 0o12

Require colorama [https://pypi.org/project/colorama/]

Future Plans

add more function & operator, bugfix.

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

dailycalc-2024.0.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

dailycalc-2024.0.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file dailycalc-2024.0.1.tar.gz.

File metadata

  • Download URL: dailycalc-2024.0.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for dailycalc-2024.0.1.tar.gz
Algorithm Hash digest
SHA256 8c16d07a844bf25a572459c817ee000aab21c982e92bb6a2c7e1934fda4161db
MD5 d5460014a59b76b2cb7eb88c02e68d6a
BLAKE2b-256 731405eac418ff02c5575df7ebf46deffbe6bddd7fef5efb6bad797a15271969

See more details on using hashes here.

File details

Details for the file dailycalc-2024.0.1-py3-none-any.whl.

File metadata

  • Download URL: dailycalc-2024.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for dailycalc-2024.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3837c2a6e556ddd1fcc50dd648f0068ff54aaea88ab5f61513642517d637f50
MD5 ee0218fe7a48947f75f6a4f0c7ef126b
BLAKE2b-256 1dc78249f976d5846e872e89d8b2c46aa25f6ae5e01eb340d18cfa4624eaa901

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