We want to create an application for the analysis of the order history at an online store. Each order is made by a customer and concerns the purchase of one or more items. Orders are stored in
OR, an array of integers having 4 columns. The generic line
OR[i] = [o, a, q, p] denotes the fact that in the order with code "o" a quantity "q" of the article with code "a" is required, sold at a unit price equal to "p" (for which obviously the total price paid for the item a in the order "o" is equal to "p * q"). An order has as many rows in
OR as there are different items contained in the order.
I must write a function "ordine_min(OR)" which returns the order code with the minimum total price. In case of a tie, any of the orders with the minimum total price must be returned.
def ordine_min(OR): ret =  for i in range(len(OR)): if prezzo(OR,i): ret.append((prezzo(OR, i),i)) return min(ret) def prezzo(OR, i): prezzo_tot = 0 for k in range(len(OR)): if OR[k] == i: prezzo_tot += OR[k] * OR[k] return prezzo_tot
The matrix is here:
OR = [[1,1,2,2], [1,2,3,2], [2,1,1,2], [2,4,1,3], [3,3,2,1], [3,4,2,1], [4,4,1,7], [4,5,2,1], [5,1,2,4], [5,5,1,4], [6,1,2,1], [6,2,1,3]]