Pretty Fractions by rolf

import re
L=len
C=lambda l,s:((l-L(s))/2*" "+s+l*" ")[:l]
while 1:
 a=re.findall("\w+|\(.*?\)|.",raw_input());x=y=z=""
 while a:
  if L(a)>2 and"/"==a[1]:u=a[0].strip("()");v=a[2].strip("()");m=max(L(u),L(v));x+=C(m,u);y+="-"*m;z+=C(m,v);a=a[3:]
  else:u=a[0];v=L(u)*" ";x+=v;y+=u;z+=v;a=a[1:]
 print"%s\n%s\n%s\n"%(x,y,z)

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

download

return to the top page