How can you accumulate exact fractions of completed work?
Fraction represents a rational number with an integer numerator and denominator and reduces it to lowest terms.
Python example and interpretation
One third plus one sixth makes exactly one half. Both increments must refer to the same total workload, or first be weighted to a common basis.
from fractions import Fraction as F
total=F(1,3)+F(1,6)
[total.numerator,total.denominator]Result [1, 2]
中文
怎样精确累计不等分任务的完成比例?
Fraction 用整数分子和分母存储有理数,并自动约为最简形式。
Python 算例与适用条件
完成三分之一再完成六分之一,共完成二分之一。两份进度应以同一个总任务为分母,任务规模不同要先加权。
from fractions import Fraction as F
total=F(1,3)+F(1,6)
[total.numerator,total.denominator]结果 [1, 2]