def build_div(ring):
    """Displays the table for division in the ring."""
    list_elems = list(ring)
    print "   " + " | ".join([str(i) for i in list_elems])

    #Main loop.
    for lst in cartesian_product(list_elems, list_elems):
        temp = []
        for i, j in lst:
            try:
                result = i / j
            except ZeroDivisionError:
                temp.append('X')
            else:
                temp.append(result)
        print ("%s| " % lst[0][0]) + " | ".join([str(i) for i in temp])
Displays the table for division in the ring.
recipes/Python/149148_Finite_Arithmetic/recipe-149148.py