(digits, skip=0, colwidth=10, columns=5)
Pretty printer for first n digits of a fraction
Pretty printer for first n digits of a fraction
Pretty printer for first n digits of a fraction
def display_fraction(digits, skip=0, colwidth=10, columns=5):
    """Pretty printer for first n digits of a fraction"""
    perline = colwidth * columns
    printed = 0
    for linecount in range((len(digits) - skip) // (colwidth * columns)):
        line = digits[skip + linecount*perline:skip + (linecount + 1)*perline]
        for i in range(columns):
            print(line[i*colwidth: (i + 1)*colwidth],)
        print(":", (linecount + 1)*perline)
        if (linecount + 1) % 10 == 0:
            print
        printed += colwidth*columns
    rem = (len(digits) - skip) % (colwidth * columns)
    if rem:
        buf = digits[-rem:]
        s = ""
        for i in range(columns):
            s += buf[:colwidth].ljust(colwidth + 1, " ")
            buf = buf[colwidth:]
        print(s + ":", printed + colwidth*columns)
def display_fraction ( digits , skip = 0 , colwidth = 10 , columns = 5 ) : perline = colwidth * columns printed = 0 for linecount in range ( ( len ( digits ) - skip ) // ( colwidth * columns ) ) : line = digits [ skip + linecount * perline : skip + ( linecount + 1 ) * perline ] for i in range ( columns ) : print ( line [ i * colwidth : ( i + 1 ) * colwidth ] , ) print ( ":" , ( linecount + 1 ) * perline ) if ( linecount + 1 ) % 10 == 0 : print printed += colwidth * columns rem = ( len ( digits ) - skip ) % ( colwidth * columns ) if rem : buf = digits [ - rem : ] s = "" for i in range ( columns ) : s += buf [ : colwidth ] . ljust ( colwidth + 1 , " " ) buf = buf [ colwidth : ] print ( s + ":" , printed + colwidth * columns )