-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobability.py
39 lines (31 loc) · 1.18 KB
/
probability.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
answers = 4
questions = 1
# Initializes all the variables
def init(q, a):
global answers
global questions
questions = q
answers = len(a)
# Returns the probability as a percentage given a number of events, taking into account the possibilities computed before
def computeProbability(events, possibilities):
return (events / possibilities) * 100
# Returns how much is added or substracted given a number of correct answers taking into account the number of questions
# Assuming addition of one point for a right answers and substraction of 0.33 for a wrong answer
def score(correctAnswers):
positive = 1
negative = 1 / (answers - 1)
return positive * correctAnswers - ((questions - correctAnswers) * negative)
# Returns the added probability for a given condition
# Possible conditions are: an positive number of points, a negative number or zero
def conditionalProbability(rightAnswers, condition, possibilities):
p = 0
for i in range(0, len(rightAnswers)):
if condition(score(i)):
p = p + computeProbability(rightAnswers[i], possibilities)
return p
def isPositive(score):
return score > 0
def isNegative(score):
return score < 0
def isZero(score):
return score == 0