import numpy as np # %% Number of trials: num_trials = 100000 # %% Params of np.random.choice(): sample_space = np.array([1, 2, 3, 4, 5, 6]) sample_size = 1 replace = True prob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6] # %% Initializing counter of event A: count_A = 0 # %% For loop simulating the n events: for k in range(0, num_trials): # Sample number k (event number k): sample_k = np.random.choice( sample_space, sample_size, replace, prob) # Updating counter if event A has occured: if ((5 in sample_k) or (6 in sample_k)): count_A += 1 # %% Calculating and printing probability estimate: prob_estimate_A = count_A/num_trials print('Estimate of prob of event A =', prob_estimate_A)