Hi,
On 6 December 2011 08:28, smichr <[email protected]> wrote:
> Is there any place in sympy for mixed representation? in pprint, a
> Rational method?
>
> >> Rational(7, 3).mixed
> '2 1/3'
> or
> (2, 1/3)
>
> I was working with a younger math class and wishing for this today.
>
You can implement a printer for this, e.g.:
class XStrPrinter(StrPrinter):
def _print_Rational(self, r):
p = abs(r.p)
q = r.q
a = p//q
b = p % q
c = q
if not a:
s = "%s/%s" % (b, c)
else:
s = "%s %s/%s" % (a, b, c)
if r.p < 0:
s = "-" + s
return s
Otherwise you can implement MixedRational class (or similar).
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
>
Mateusz
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.