- #1

- 2,136

- 2,711

Python:

```
import numpy as np
global m, n, p, q, arr1, arr2def input():
# Input for first matrix:
print("Enter the number of rows of the first matrix: ", end="")
globals()['m'] = int(input())
print("Enter the number of columns of the first matrix: ", end="")
globals()['n'] = int(input())
print("\nEnter the first matrix: ")
globals()['arr1'] = np.empty((m, n))
for i in range(0, m):
for j in range(0, n):
print("Enter the element in cell [", i, " ][", j, "]: ", end="")
arr1[i][j] = eval(input())
print("\nThe first matrix is: ")
printMatrix(arr1)
# Input for second matrix:
print("Enter the number of rows of the second matrix: ", end="")
globals()['p'] = int(input())
print("Enter the number of columns of the second matrix: ", end="")
globals()['q'] = int(input())
print("\nEnter the first matrix: ")
globals()['arr2'] = np.empty((p, q))
for i in range(0, p):
for j in range(0, q):
print("Enter the element in cell [", i, " ][", j, "]: ", end="")
arr2[i][j] = eval(input())
print("\nThe second matrix is: ")
printMatrix(arr2)
multiply_check()def printMatrix(arr: np.ndarray):
passdef multiply_check():
pass
input()
```

`multiply_check()`

and `printMatrix()`

.As you can see, I am calling the static function

`input()`

. My program has been built such that `input() `

will call the other functions.I get a RecursionError when I run this file:

There is no recursion anywhere in the program. I don't understand how line 8 is calling itself recursively.

If I enclose everything inside a class, including the declaration for global variables, the program executes properly. Also, if I remove the functions and write the program without functions, it works properly. (I do not prefer doing the latter, this was just for debugging).

I tried removing the global variables and then passing the local variables as parameters in function calls, but no luck. Same problem at the same point.

I faced the same problem a few days back with a different program in a different computer. I executed each line in the command line, and everything executed properly.

Any idea why this problem is occurring?

Python version: 3.7.4, Numpy version: 1.17.3