- <code class="doc-symbol doc-symbol-toc doc-symbol-module"></code>&nbsp;calculator
- <code class="doc-symbol doc-symbol-toc doc-symbol-function"></code>&nbsp;add
- <code class="doc-symbol doc-symbol-toc doc-symbol-function"></code>&nbsp;divide
- <code class="doc-symbol doc-symbol-toc doc-symbol-function"></code>&nbsp;multiply
- <code class="doc-symbol doc-symbol-toc doc-symbol-function"></code>&nbsp;subtract
Python package docs
calculator
Provide several sample math calculations.
This module allows the user to make mathematical calculations.
Examples:
>>> from calculator import calculations
>>> calculations.add(2, 4)
6.0
>>> calculations.multiply(2.0, 4.0)
8.0
>>> from calculator.calculations import divide
>>> divide(4.0, 2)
2.0
The module contains the following functions:
add(a, b)
- Returns the sum of two numbers.subtract(a, b)
- Returns the difference of two numbers.multiply(a, b)
- Returns the product of two numbers.divide(a, b)
- Returns the quotient of two numbers.
add
Compute and return the sum of two numbers.
Examples:
>>> add(4.0, 2.0)
6.0
>>> add(4, 2)
6.0
Parameters:
-
a
(int | float
) –A number representing the first addend in the addition.
-
b
(int | float
) –A number representing the second addend in the addition.
Returns:
-
float
–A number representing the arithmetic sum of
a
andb
.
divide
Compute and return the quotient of two numbers.
Examples:
>>> divide(4.0, 2.0)
2.0
>>> divide(4, 2)
2.0
>>> divide(4, 0)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
Parameters:
-
a
(int | float
) –A number representing the dividend in the division.
-
b
(int | float
) –A number representing the divisor in the division.
Returns:
-
float
–A number representing the quotient of
a
andb
.
Raises:
-
ZeroDivisionError
–An error occurs when the divisor is
0
.
multiply
Compute and return the product of two numbers.
Examples:
>>> multiply(4.0, 2.0)
8.0
>>> multiply(4, 2)
8.0
Parameters:
-
a
(int | float
) –A number representing the multiplicand in the multiplication.
-
b
(int | float
) –A number representing the multiplier in the multiplication.
Returns:
-
float
–A number representing the product of
a
andb
.
subtract
Calculate the difference of two numbers.
Examples:
>>> subtract(4.0, 2.0)
2.0
>>> subtract(4, 2)
2.0
Parameters:
-
a
(int | float
) –A number representing the minuend in the subtraction.
-
b
(int | float
) –A number representing the subtrahend in the subtraction.
Returns:
-
float
–A number representing the difference between
a
andb
.