Skip to main content

A calculator that evaluates string expressions both locally or using WolframAlpha.

Project description

calcalc: a toy calculator

This is a calculator for evaluating string expressions (e.g. '2*sin(3/5)', 'mass of the sun in kg'). The statement can be computed either locally or through querying WolframAlpha.

To install using pip: pip install calcalc-toy. To install via GitHub:

There are two ways to interact with the package:

Usage 1: from command line

Examples (inside the CalCalc folder):

This command evaluate a simple expression locally with the -s argument:

$ python -s '2*sin(3)'

This command calculates the mass of the moon through Wolfram with the -w argument. The result is displayed as a plain text:

$ python -w 'mass of the moon in kg'
7.3459×10^22 kg (kilograms)

If we want to display a float instead, use the --float flag:

$ python -w 'mass of the moon in kg' --float

Usage 2: inside python script/ipython

After pip install, import the calculator like this:

from calcalc.CalCalc import calculate

We can evaluate a simple expression locally:

In [1]: calculate('2*sin(3/5)+log(7)')
Out[2]: 3.075195095845384

We can evalute a Wolfram query using local=False:

In [1]: calculate('mass of the moon in kg', local=False)
Out[2]: 7.3459e+22

The default Wolfram output using python script/ipython is converted float to facilitate further computations (opposite to the command line behavior described above). To display a string instead, use return_float=False:

In [1]: calculate('mass of the moon in kg', local=False, return_float=False)
Out[2]: '7.3459×10^22 kg (kilograms)'

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

calcalc-toy-1.8.tar.gz (8.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page