The floor division operator, // , expresses integer division, which rounds
down the fractional part of the result of division.
If you want to change selection, open document below and click on "Move attachment"
2.2 Data Abstractionms before constructing the pair. As
with many useful tools, such a function already exists in the Python Library.
>>> from fractions import gcd
>>> def rational(n, d):
g = gcd(n, d)
return (n//g, d//g)
<span>The floor division operator, // , expresses integer division, which rounds
down the fractional part of the result of division. Since we know that g
divides both n and d evenly, integer division is exact in this case.
This revised rational implementation ensures that rationals are expressed
in lowest te Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details