formatting output with for loop or different method in python
<p>I did a program to calculate the inventory in python;however, i have problem formatting the layout output. What I have done so far is:</p>

<pre><code>def summary(a,b,c,row,col,tot):
    d={0:"Small", 1:"Medium", 2:"Large", 3:"Xlarge"}
    for i in range(row):
        for j in range(col):
            print "%6d" %(a[i][j]),
        print "%s%6d\n" %(d[i],(b[i])),
    print "\n" ,
    for j in range(col):
        print "%6d" %(c[j]),
    print "%6d\n" %tot
</code></pre>

<p>so the output comes the 7 x 4 matrix and the total to the right hand side and by column total. However I want to put some names on the left hand side to represent the specific name like size small etc so i used a dictionary but what i am getting is on the right hand side just before the row total. I can't figure out how can i put it on the left hand side in the same row as the numbers. I want to put two columns apart from the number (matrix) which one would be a size in the first far left column in the middle and then in second column names as u can see specified used in dictionary and then the numbers would come in the same row.</p>

<p>Thanks a lot for any help or suggestions.  I did a program to calculate the inventory in python;however, i have problem formatting the layout output. What I have done so far is:</p>

<pre><code>def summary(a,b,c,row,col,tot):
    d={0:"Small", 1:"Medium", 2:"Large", 3:"Xlarge"}
    for i in range(row):
        for j in range(col):
            print "%6d" %(a[i][j]),
        print "%s%6d\n" %(d[i],(b[i])),
    print "\n" ,
    for j in range(col):
        print "%6d" %(c[j]),
    print "%6d\n" %tot
</code></pre>

<p>so the output comes the 7 x 4 matrix and the total to the right hand side and by column total. However I want to put some names on the left hand side to represent the specific name like size small etc so i used a dictionary but what i am getting is on the right hand side just before the row total. I can't figure out how can i put it on the left hand side in the same row as the numbers. I want to put two columns apart from the number (matrix) which one would be a size in the first far left column in the middle and then in second column names as u can see specified used in dictionary and then the numbers would come in the same row.</p>

<p>Thanks a lot for any help or suggestions.  </p>

<p>I want it to look like this</p>

<pre><code> small   1 1 1 1 1 1 1  7
 medium  1 1 1 1 1 1 1  7
</code></pre>

<p>size large   1 1 1 1 1 1 1  7  </p>

<pre><code> xlarge  1 1 1 1 1 1 1  7
         4 4 4 4 4 4 4  28
</code></pre>

<p>and i get</p>

<p>1 1 1 1 1 1 1 small 7</p>

<p>1 1 1 1 1 1 1 medium 7</p>

<p>1 1 1 1 1 1 1 large 7</p>

<p>1 1 1 1 1 1 1 xlarge 7</p>

<p>4 4 4 4 4 4 4 28</p>

<p>sorry for not being specific enough previously.</p>
