Python program to Check Rows and Columns that Has Particular Element

from random import random
row = 5
col = 10
matrix = []
for i in range(row):
 myrow = []
 for j in range(col):
    myrow.append(int(random()*50)+10)
 matrix.append(myrow)
for myrow in matrix:
 print(myrow)
num = int(input("Range of numbers(10-50): "))
print("Rows: ", end=' ')
for i in range(row):
 if num in matrix[i]:
    print(i,end=' ')
print()
print("Columns: ",end=' ')
for j in range(col):
 for i in range(row):
    if matrix[i][j] == num:
        print(j, end=' ')
        break
print()

 

 

Output:

[24, 52, 20, 43, 37, 58, 48, 24, 17, 51]
[41, 36, 53, 12, 32, 49, 56, 26, 58, 10]
[43, 10, 50, 39, 44, 13, 56, 10, 49, 13]
[20, 32, 27, 33, 23, 43, 42, 55, 36, 59]
Range of numbers(10-50): 24
Rows:  1
Columns:  0 7

 

 

[10, 42, 51, 10, 41, 27, 41, 18, 55, 51]
[55, 51, 16, 25, 12, 16, 33, 33, 18, 49]
[55, 35, 49, 10, 37, 57, 32, 37, 59, 54]
[35, 18, 37, 15, 12, 11, 58, 12, 21, 46]
[19, 50, 26, 28, 25, 40, 48, 59, 38, 16]
Range of numbers(10-50): 37
Rows:  2 3
Columns:  2 4 7

 

Subscribe For Daily Updates