Multiply a Column X61103


Statement
 

pdf   zip   main.py

html

Write a function prod_col(i, m) that receives the index i of one column of a matrix of int’s m and returns the product of all the integers in that column. The matrix of int’s is represented as a tuple of rows, each row being, in turn, a tuple of int’s. If m has n columns, we are guaranteed that 0 ≤ i < n.

Observation

Observe that 0 ≤ i < n implies that the rows of m, if any, have that column and are hence nonempty, but nothing else.

Sample session
>>> prod_col(0, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10)))
320
>>> prod_col(0, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10))) + prod_col(2, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10)))
276
>>> prod_col(1, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10)))
0
Information
Author
José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python