Write a program to randomly fill in 0s and 1s into a 4x4 2- dimension list, print the list and find the rows and columns with the most number of 1s in python
Code
for i in range(4):for j in range(4):print(l[i][j], end=" ")print()# print the list and find the rows and columns with the most number of 1smax_row = 0max_col = 0row_no = 0col_no = 0for i in range(4):row = 0col = 0for j in range(4):if l[i][j] == 1:row += 1if l[j][i] == 1:col += 1if row > max_row:max_row = rowrow_no = iif col > max_col:max_col = colcol_no = iprint("Row with most number of 1s is row", row_no, "with", max_row, "1s")print("Column with most number of 1s is column", col_no, "with", max_col, "1s")
0 Comments
Post a Comment