J
J
Johnem2020-04-20 21:56:44
Python
Johnem, 2020-04-20 21:56:44

How to multiply the values ​​of n tables, and then add the resulting values ​​n times?

How to do something similar to the sum of products from exel, in the i position of the list there is a list with values ​​\u200b\u200bthat need to be multiplied, and then add all possible products together. So for a list like this:

sale_transactions = 

The answer should be 103462, or otherwise the sum of the numbers given by the following code:
for i in range(0, len(sale_transactions)):
    sale_transactions[i][4] * sale_transactions[i][5]
    print(purchase_transactions)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
1
101-s, 2020-04-21
@Johnem

I understood only from the 10th time what it was about -))
you can do it like this:

sum = 0
for row in sale_transactions:
   sum += row[4] * row[5]
print(sum)

To understand your language, you need common words that everyone else will understand
YOUR question:
How to multiply the values ​​of n tables, and then add the resulting values ​​n times?

["03/16/2020 12:31:00 PM", "RUB", "BANEP", "sale", 47, 1294, "SBER", "MOEX"] - this is called a list and not a table, in python there is no such thing as the sale_transactions table
is also a list, which consists of lists

S
scottparker, 2020-04-20
@scottparker

Do you yourself understand what you need to multiply and add? )
and your meaningless)

for i in range(0, len(sale_transactions)):
    sale_transactions[i][4] * sale_transactions[i][5]
    print(purchase_transactions)

D
dmshar, 2020-04-21
@dmshar

second line in code

purchase_transactions=purchase_transactions+sale_transactions[i][4] * sale_transactions[i][5]

Well, the last line, of course, without otsupov.
And how much she counts - counts so much.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question