Python-Matrix Addition

This code defines a function mat_add that adds three matrices A, B, and C. def mat_add(A,B,C): if(len(A)==len(B) and (len(B)==len(C)) and (len(A[0])==len(B[0])) and (len(B[0])==len(C[0]))): for i in range(len(A)): for j in range(len(A[0])): A[i][j]=A[i][j]+B[i][j]+C[i][j] return A else: return -1 A=[[1,2,3],[1,2,3],[2,4,6]] B=[[1,2,3],[1,2,3],[2,4,6]] C=[[1,2,3],[1,2,3],[2,4,7]] x=mat_add(A,B,C) print(x) Here’s a line-by-line explanation of the function : def mat_add(A, B, C):This line…

Python-Prime Check and Prime Count

prime check: The below programs will show you how to check a given number is prime or not and count the number of primes in a list. The function is_prime(n) determines whether a given number n is a prime number. It first checks if n is less than 2; if so, the function returns False…