""" Write a function div3_2d that has one parameter - 2d list of integers. Function finds and returns the number of elements that are divisible by 3. Function also creates and returns the new ONE-DIMENSIONAL list that includes all elements that are divisible by 3. Write a program that first randomly generates row and col, we will assume that each row has the same number of elements, col. Program then randomly generates two dimensional list of integers in range -5 to 5. Program uses function div3_2d to find the number of elements divisible by 3 and prints all elements divisible by 3. Use these functions to generate the list and print 2d list in table form. """ import random def div3_2d(list2d): div3=[] #solution 1 row=len(list2d) col=len(list2d[0]) for i in range(row): for j in range(col): if(list2d[i][j]%3==0): div3.append(list2d[i][j]) return div3, len(div3) def div3_2d_ver2(list2d): div3=[] #solution 2 for list in list2d: for item in list: if(item%3==0): div3.append(item) return div3, len(div3) def make_list_random2d(row, col, min, max): return [[random.randint(min,max) for i in range(col)] for j in range(row)] def print_matrix(list2d): for list in list2d: print(list) def main(): """ list2d=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] div3, count=div3_2d(list2d) #row=4, col= 3 print(div3) #[3,6,9,12] print(count) #4 """ row=random.randint(2,5) col=random.randint(2,5) list2d=make_list_random2d(row, col, -5,5) div3, count=div3_2d(list2d) print_matrix(list2d) print("div by 3") print(div3) print("counter",count) main()