""" What is the average result of a six-sided die? To find out, we will write a simple Monte-Carlo simulation. (1) Simulate the result of a six-sided die 100 times using a for-loop. """ import numpy as np n_dice = 100 n_sides = 6 results = np.random.randint(1, n_sides + 1, size=n_dice) """ (2) Calculate the mean, variance, and standard deviation of the simulations. Hint: NumPy has built-in functions for this """ average_result = np.mean(results) variance = np.var(results) standard_deviation = np.std(results) """ (3) Calculate the standard error (`SE`) of your simulations defined as the ratio of the standard deviation and the square root of the number of results (`n`). ``` standard deviation SE = ────────────────── √n ``` *Background* The standard error tells you how close you expect your calculated mean to be to the true mean. Specifically, if you were to perform your simulation twenty times, then nineteen out of twenty times the true mean lies within the interval `estimated_mean +- 1.96 * SE`. This is called the 95% confidence interval. """ standard_error = standard_deviation / np.sqrt(n_dice) """ (4) Print the 95% confidence interval to the console using an f-string. Make sure to use a full sentence. """ print( f"The average result of a {n_sides}-sided die", f"is {average_result:.2f} with a", f"95% confidence interval of {average_result:.2f}+-{1.96 * standard_error:.2f}" ) """ (5) Make your code more readable. (a) Get rid of the for-loop by instead using a NumPy array. Hint: There is a parameter in all of the NumPy random functions that allows you to calculate many random values at once. (b) If you have not done so, remove the hard-coding from the number dice as well as the number of sides of each die. Both of these values should be stored in a variable with a meaningful name. """