A basic utility designed to prettify and visualize fractions.
- A terminal accepting ANSI codes
Displaying a prettified fraction from a number:
>>> import hyphenfrac, random
>>> hyphenfrac.visualize_number(random.randint(1, 100)/random.randint(1, 100))
20
-- + 1
49
>>>
You may also assign this value to a variable:
>>> import hyphenfrac
>>> foo = hyphenfrac.make_pretty(1, 10)
>>> print(foo)
1
--
10
>>>
You can optionally use a dash instead of a hyphen-minus character for a vinculum:
>>> import hyphenfrac
>>> hyphenfrac.visualize("ln(x) - ln(y)", "x - y", hyphen=False)
ln(x) - ln(y)
―――――――――――――
x - y
>>>
Fractions could also be used as their own object:
>>> from hyphenfrac import Fraction
>>> myFrac = Fraction(numerator="Vd", denominator="CL", operation="", whole="ln(2)", hyphen=False)
>>> myFrac.display()
Vd
―― ln(2)
CL
>>> isinstance(myFrac, Fraction)
True
>>>