Formula with a score given binary answers and if-else

21 Views Asked by At

Assume we have 5 questions in a quiz and all five has different scores:

>>> x = [1, 2, 3, 4, 5]

And there is a binary test where a question is either right or wrong, and the answers are:

>>> correct = [0, 0, 1, 0, 1]

To calculate the overall score, in code, it will be:

>>> sum(i for i,j in zip(x, correct) if j)
8

How should the summation above be expressed in math formula?

In a strange manner, I've tried this by adding more variables to say that j belongs to i' where i' are the no. of questions correct:

enter image description here

but there must be a simpler formulation!

1

There are 1 best solutions below

0
On

This looks correct to me. I don't think that there is a simpler form, and see no reason to assume that there must be one