mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
Numerical operations: the return!
Instructions
Create a file numerical_operations_the_return.py
containing the following functions:
modulo(a, b)
divide(a, b)
integer_division(a, b)
We assume that a
and b
are numbers (int
or float
).
In case of a division by zero or modulo zero your functions should return
0
.
Usage
Here is a possible test.py
to test your functions:
import numerical_operations_the_return
print(numerical_operations_the_return.modulo(10, 3))
print(numerical_operations_the_return.divide(10, 3))
print(numerical_operations_the_return.divide(10, 0))
print(numerical_operations_the_return.integer_division(10, 3))
$ python3 test.py
1
3.3333333333333335
0
3
$
Hints
- Some operations will panic in special cases (like division by zero), it is very important to always account for those cases and handle them properly in order to avoid bugs.
- In
Python 2
a division with two integers will return an integer, inPython 3
it will return a float. We assume you are usingPython 3
, in case you want to force thePython 3
behavior you can cast one of the operands to float like so:float(a)
.