Pretty Fractions by hallvabo

import re
while 1:
 r=s=t='';a=re.findall('\w+|[*+/=]|\([^)]+\)',raw_input());p=a.pop
 while a:
\x09u=p(0)
\x09if'/'in a[:1]:u=u.strip('()');p(0);v=p(0).strip('()');m=max(len(u),len(v));s+='-'*m
\x09else:s+=u;m=len(u);u=v=' '
\x09r+=u.center(m);t+=v.center(m)
 print"%s\n"*3%(r,s,t)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page