Calculations
sandbox.calculations
¶
Provide several sample math calculations.
This module allows the user to make mathematical calculations.
Classes:
-
Two_numbers–Several sample math calculations using two numbers.
Functions:
-
add–Compute and return the sum of two numbers.
-
subtract–Calculate the difference of two numbers.
-
multiply–Compute and return the product of two numbers.
-
divide–Compute and return the quotient of two numbers.
Classes¶
Two_numbers(first, second)
¶
Several sample math calculations using two numbers.
Examples:
| Python Console Session | |
|---|---|
1 2 3 4 | |
Parameters:
Methods:
-
add–Add my two numbers, and if additional numbers are provided, add them to the sum.
-
subtract–Subtract my two numbers.
-
multiply–Multiply my two numbers.
-
divide–Divide my two numbers.
Attributes:
Source code in sandbox\calculations.py
| Python | |
|---|---|
22 23 24 25 26 27 28 29 30 31 32 | |
Attributes¶
first: Union[float, int] = first
instance-attribute
¶
The first number.
second = second
instance-attribute
¶
The second number.
Functions¶
add(*args)
¶
Add my two numbers, and if additional numbers are provided, add them to the sum.
Returns:
Source code in sandbox\calculations.py
| Python | |
|---|---|
35 36 37 38 39 40 41 42 43 | |
subtract()
¶
Subtract my two numbers.
Source code in sandbox\calculations.py
| Python | |
|---|---|
45 46 47 | |
multiply()
¶
Multiply my two numbers.
Source code in sandbox\calculations.py
| Python | |
|---|---|
49 50 51 | |
divide()
¶
Divide my two numbers.
Source code in sandbox\calculations.py
| Python | |
|---|---|
53 54 55 | |
Functions¶
add(a, b)
¶
Compute and return the sum of two numbers.
Examples:
>>> add(4.0, 2.0)
6.0
>>> add(4, 2)
6.0
Parameters:
-
a(Union[float, int]) –A number representing the first addend in the addition.
-
b(Union[float, int]) –A number representing the second addend in the addition.
Returns:
-
float–A number representing the arithmetic sum of
aandb.
Source code in sandbox\calculations.py
| Python | |
|---|---|
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
subtract(a, b)
¶
Calculate the difference of two numbers.
Examples:
>>> subtract(4.0, 2.0)
2.0
>>> subtract(4, 2)
2.0
Parameters:
-
a(Union[float, int]) –A number representing the minuend in the subtraction.
-
b(Union[float, int]) –A number representing the subtrahend in the subtraction.
Returns:
-
float–A number representing the difference between
aandb.
Source code in sandbox\calculations.py
| Python | |
|---|---|
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
multiply(a, b)
¶
Compute and return the product of two numbers.
Examples:
>>> multiply(4.0, 2.0)
8.0
>>> multiply(4, 2)
8.0
Parameters:
-
a(Union[float, int]) –A number representing the multiplicand in the multiplication.
-
b(Union[float, int]) –A number representing the multiplier in the multiplication.
Returns:
-
float–A number representing the product of
aandb.
Source code in sandbox\calculations.py
| Python | |
|---|---|
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
divide(a, b)
¶
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(Union[float, int]) –A number representing the dividend in the division.
-
b(Union[float, int]) –A number representing the divisor in the division.
Returns:
-
float–A number representing the quotient of
aandb.
Raises:
-
ZeroDivisionError–An error occurs when the divisor is
0.
Source code in sandbox\calculations.py
| Python | |
|---|---|
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |