Multiply a Row X35644


Statement
 

pdf   zip   main.py

thehtml

Write a function prod_row(i, m) that receives the index i of one row of a matrix of int’s m and returns the product of all the integers in that row. 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 rows, we are guaranteed that 0 ≤ i < n.

Observation

Observe that 0 ≤ i < n implies that the tuple m is nonempty, but nothing else.

Sample session
>>> prod_row(1, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10)))
24
>>> prod_row(1, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10))) + prod_row(2, ((8, 0, 2, -1), (4, 3, 2, 1), (10, 11, -11, -10)))
12124
>>> prod_row(0, ((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