# matrix_intro.py
#
# the program asks the user for the matrix size:
# number of rows and number of columns, then
# then creates a matrix filled with random numbers from interval [-5,5]
from random import randint
def main():
print("This program build a matrix of size n by m," )
print("where n in the number of rows and m is the number of colums.")
rows = int(input("Enter the number of rows (positive integer):"))
columns = int(input("Enter the number of columns (positive integer):"))
A = []
for i in range(rows * columns):
value = randint(-5,5) # generate a random integer from the range [-5,5]
A.append(value)
print(A)
# at this moment we didn't cover the nested loops,
# so we cannot display the list as a rows x columns matrix
# diregard the next block - we will cover it later
for i in range(rows):
for j in range(columns):
print(A[i*columns + j],end = '\t')
print()
# Now let's display the elements by their indices
print("Now we can print the elements of the matrix, a_ij")
r = int(input("Enter the index i (in which row):"))
c = int(input("Enter the index j (in which column):"))
print("a_",i,j," = ",A[(r-1)*columns + (c-1)])
main()