Page 631 - ComputerScience_Class_11
P. 631
40. Write a program to generate a square matrix of a given size.
Program 40.py
File Edit Format Run Options Window Help
size = int(input("Enter the size of the matrix: "))
matrix = []
i = 0
while i < size:
row = []
j = 0
while j < size:
row.append("R" + str(i+1) + "C" + str(j+1))
j += 1
matrix.append(row)
i += 1
for row in matrix:
print(row)
The output of the preceding program is as follows:
Output
Enter the size of the matrix: 5
['R1C1', 'R1C2', 'R1C3', 'R1C4', 'R1C5']
['R2C1', 'R2C2', 'R2C3', 'R2C4', 'R2C5']
['R3C1', 'R3C2', 'R3C3', 'R3C4', 'R3C5']
['R4C1', 'R4C2', 'R4C3', 'R4C4', 'R4C5']
['R5C1', 'R5C2', 'R5C3', 'R5C4', 'R5C5']
Internal Assessment 629

