Skip to main content

Simple arithmetic lib for students

Project description

_rithmetic_

“rithmetic” is a budding python library which aims to provide arithmetic and math assistance to students using python to build math related functionality or apps.

How to Install:

Run the following command in Terminal/CLI –

  • pip install rithmetic

If you are updating to a new version of rithmetic:

  • pip install rithmetic --force-reinstall

After installation completes, run the following command in Terminal/CLI to see the welcome message –

  • rith

To check the version of rithmetic, run the following command in Terminal/CLI –

  • rith-version

License and terms of use:

rithmetic comes with the MIT license which means that anyone, anywhere can use it for any open source or even closed source application.

Current functionality:

  1. Convert a number from one base to another (Converters)
  2. Check/Verify if a number is from a specified base (Verifiers)
  3. Add, Subtract, Multiply and Divide any two numbers in desired base (Operators)

Best way to import:

Import all the functions from rithmetic at once

from rithmetic import *

Functions:

Converters

base(num, fromB, toB)

Converts any number from one base to another. (supported bases are base-2 to base-16)

num – any number | can be int or float or str type

fromB – base of ‘num’ | can be both int and str type

toB – ‘num’ gets converted to this base | can be both int and str type

Returns – The converted number in int or str or float type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

number = base(1111,2,16)
print(number)

This will print ‘F’. As 1111 in binary gets converted to F in hexadecimal.

dectosub(num, toB)

Converts any number from Decimal to any other sub-decimal base. (supported bases are base-2 to base-9)

num – any number | can be int or float or str type

toB – ‘num’ gets converted to this base | can be both int and str type

Returns – The converted number in int or str type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

number = dectosub(23,5)
print(number)

This will print 43. As 23 in decimal gets converted to 43 in base-5.

subtodec(num, fromB)

Converts any number from any sub-decimal base to Decimal. (supported bases are base-2 to base-9)

num – any number | can be int or float or str type

fromB – base of ‘num’ | can be both int and str type

Returns – The converted number in int or float type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

number = subtodec(25,6)
print(number)

This will print 17. As 25 in base-6 gets converted to 17 in decimal.

Quick single parameter converters

  • Decimal to another base:

dectob2(num)

dectob3(num)

dectob4(num)

dectob5(num)

dectob6(num)

dectob7(num)

dectob8(num)

dectob9(num)

dectob11(num)

dectob12(num)

dectob13(num)

dectob14(num)

dectob15(num)

dectob16(num)

num – any number | can be int or float or str type

Return – The converted number in int or str type OR ‘Invalid number’

  • Any base to Decimal

b2todec(num)

b3todec(num)

b4todec(num)

b5todec(num)

b6todec(num)

b7todec(num)

b8todec(num)

b9todec(num)

b11todec(num)

b12todec(num)

b13todec(num)

b14todec(num)

b15todec(num)

b16todec(num)

num – any number | can be int or float or str type

Return – The converted number in int or float type OR ‘Invalid number’

Verifiers

chkbase(num, base)

Checks if a number is from a specified base. (supported bases are base-2 to base-16)

num – any number | can be int or float or str type

base – base of ‘num’ to be checked | can be both int and str type

Returns – True OR False OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

check = chkbase('23F',16)
print(check)

This will print True. As 23F is from base-16.

Quick single parameter verifiers

chk2(num)

chk3(num)

chk4(num)

chk5(num)

chk6(num)

chk7(num)

chk8(num)

chk9(num)

chk10(num)

chk11(num)

chk12(num)

chk13(num)

chk14(num)

chk15(num)

chk16(num)

num – any number | can be int or float or str type

Return – True OR False OR ‘Invalid number’

Operators

add(num1, num2, Base)

Adds two numbers in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be int or float or str type

num2 – any number, which will be added to ‘num1’ | can be int or float or str type

Base– base of num1 and num2 | can be both int and str type

Returns – The resultant number in int or str type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

sum = add('2a',12,11)
print(sum)

This will print 41. As (2a + 12) in base-11 is 41.

sub(num1, num2, Base)

Subtracts one number from another in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be int or float or str type

num2 – any number, which will be subtracted from ‘num1’ | can be int or float or str type

Base– base of num1 and num2 | can be both int and str type

Returns – The resultant number in int or str type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

diff = sub(23,'6e',16)
print(diff)

This will print -4B. As (23 – 6E) in base-16 is -4B.

mul(num1, num2, Base)

Multiplies two numbers in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be int or float or str type

num2 – any number, which will be multiplied with ‘num1’ | can be int or float or str type

Base– base of num1 and num2 | can be both int and str type

Returns – The resultant number in int or str type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import *

prod = mul(12,24,11)
print(prod)

This will print 288. As (12 * 24) in base-11 is 288.

div(num1, num2, Base)

Divides a number by another in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be int or float or str type

num2 – any number, ‘num1’ will be divided by this | can be int or float or str type

Base– base of num1 and num2 | can be both int and str type

Returns – The resultant number in int or str type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rith import *

quo = div(22,13,13)
print(quo)

This will print 1.99999999999999. AS (22 / 13) in base-13 is 1.99999999999999

Disclaimer – rithmetic functions do not round off any numbers and the max level of decimal points is set to 100. So, you will find some str type output values with a large number of decimal points (limited to a max of 100).

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

rithmetic-0.0.14.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

rithmetic-0.0.14-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file rithmetic-0.0.14.tar.gz.

File metadata

  • Download URL: rithmetic-0.0.14.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for rithmetic-0.0.14.tar.gz
Algorithm Hash digest
SHA256 be2144736254066d70abcd11ed5aeef97539f0503f2477ad333eb80a158f5fd2
MD5 27873e23454685c1833dc636a57781dc
BLAKE2b-256 e6af9c246d80842bb32c209eac33fc67e664290a5cd8bce19e56e495b149c45b

See more details on using hashes here.

File details

Details for the file rithmetic-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: rithmetic-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for rithmetic-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5870baab3fc998dd1fd0012a3555ccb17aa0fe76b4e1a004bbaad464496fae4c
MD5 88739aadcc92b567c273c153637684b5
BLAKE2b-256 5f6d3028071d31b976b3a57fed67e4a3a31e0d9ddf9c48cc8a5fac1c6f36f138

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