Trying to add two matrices with numbers entered as a string and then display solution, but trouble with stdin and stdout
<p>It's a programming task to enter two matrices using stdin and then display the result in stdout. I often found runtime error or no stdin or stdout to display while the program is running good.</p>

<p>This is my code for addition of two matrices.</p>

<pre><code>       """The constraint is the numbers will be entered only without any 
          string to be seen on console and also that to be in the same
          fashion being each number input separated by a white space."""
          import sys

            def main():

            num1 = []
            num2 = []

            rc1 = raw_input().split(' ')
            rc1_arr = [int(z) for z in rc1]
            r1 = rc1_arr[0]
            c1 = rc1_arr[1]
            while(r1 != 0):
                    mat1 = raw_input().split(' ')
                    arr1 = [int(z1) for z1 in mat1]
                    num1.append(arr1)
                    r1=r1-1

            rc2 = raw_input().split(' ')
            rc2_arr = [int(z) for z in rc2]
            r2 = rc2_arr[0]
            c2 = rc2_arr[1]
            while(r2 != 0):
                    mat2 = raw_input().split(' ')
                    arr2 = [int(z2) for z2 in mat2]
                    num2.append(arr2)
                    r2=r2-1

            for i in range(max(rc1_arr[0],rc2_arr[0])):
                 for j in range(max(rc1_arr[1],rc2_arr[1])):
                     su = num1[i][j]+num2[i][j]
                     sys.stdout.write(str(su))
                     sys.stdout.write(" ")
                 sys.stdout.write("\n")

        main()

       """ while running in idle it looks like this
       ##The input part is:
       3 3         ## represents no. of rows and columns
       1 2 3       ## This is the matrix 1 of 3*3
       4 5 6
       7 8 9
       3 3         ## represents no. of rows and columns for second matrix
       1 1 1       ## This is the matrix 2 of 3*3
       1 1 1
       1 1 1
       ## And the output is like:
       2 3 4       ## Sum of the above two matrices.
       5 6 7 
       8 9 10
       """
</code></pre>

<p>Please help.</p>

<p>You could have some problem with the indentation... I did not touch a line (other than adjust the indentation and it work as expected!)</p>

<pre><code>#!/usr/bin/env pyhton2
import sys

def main():

    num1 = []
    num2 = []

    rc1 = raw_input().split(' ')
    rc1_arr = [int(z) for z in rc1]
    r1 = rc1_arr[0]
    c1 = rc1_arr[1]
    while(r1 != 0):
        mat1 = raw_input().split(' ')
        arr1 = [int(z1) for z1 in mat1]
        num1.append(arr1)
        r1=r1-1

    rc2 = raw_input().split(' ')
    rc2_arr = [int(z) for z in rc2]
    r2 = rc2_arr[0]
    c2 = rc2_arr[1]
    while(r2 != 0):
        mat2 = raw_input().split(' ')
        arr2 = [int(z2) for z2 in mat2]
        num2.append(arr2)
        r2=r2-1

    for i in range(max(rc1_arr[0],rc2_arr[0])):
        for j in range(max(rc1_arr[1],rc2_arr[1])):
            su = num1[i][j]+num2[i][j]
            sys.stdout.write(str(su))
            sys.stdout.write(" ")
        sys.stdout.write("\n")

main()
</code></pre>

python matrix stdout stdin sys