File size: 1,296 Bytes
389d072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from visma.io.tokenize import tokenizer


def simpleProbability(sampleSpace, requiredEvent=None):
    """Implements simple probability

    Arguments:
        sampleSpace -- {visma.discreteMaths.statistics.ArithemeticMean}
        requiredEvent -- {Event whose probability is to be calculated}

    Returns:
        token_string {string} -- final result stored in a string
        animation {list} -- list of equation solving process
        comments {list} -- list of comments in equation solving process
    """

    animations = []
    comments = []
    events = []
    token_string = ''
    if sampleSpace.values is not []:
        events.extend(sampleSpace.values)
        totalOccurances = len(events)
        animations += [[]]
        comments += [['The total occurances are ' + str(totalOccurances)]]
        requiredOccurances = events.count(requiredEvent)
        animations += [[]]
        comments += [['The occurances of required event are ' + str(requiredOccurances)]]
        probability = requiredOccurances/totalOccurances
        comments += [['Hence, Required probability is: ']]
        animations += [tokenizer('P = ' + str(probability))]
        token_string = 'P = ' + str(probability)
        return token_string, animations, comments
    else:
        return '', [], []