why my code doesn’t work? what’s the problem?
import numpy as np

Simulate rolling a fair 6-sided dice 10000 times
num_rolls = 10000
dice_outcomes = np.random.choice(6, num_rolls) + 1 # Adding 1 to get outcomes from 1 to 6

Calculate the mean and variance
mean = np.mean(dice_outcomes)
variance = np.var(dice_outcomes)

Print the results with three decimal places
print(f"Mean: {mean:.3f}“)
print(f"Variance: {variance:.3f}”)

Does it output any error?

these are results Mean: 3.492
Variance: 2.903
but I didn’t get any score for this question and it was strange
this code didn’t give me any error but there was no grade for me

not at all
but I didn’t get any score for my answer 0/10

TMosh
October 5, 2023, 4:27am
6
The notes in the notebook says Exercise 1 is not a graded part of the assignment.

TMosh
October 5, 2023, 4:43am
7
Before you do this assignment, be sure you study the previous lab on simulating dice with Numpy.

yeah I know @TMosh I’m not as stupid as you think

TMosh
October 9, 2023, 9:27pm
9
That’s not the correct result to within 0.001.
You can exactly compute the correct result easily by adding the integers 1 through 6 and dividing by 6.

Since each die value is equally probable, you don’t need a statistical simulation.

TMosh
October 9, 2023, 9:35pm
10
Similarly, the variance is the mean of the squared errors.

So you compute the difference between the mean and each value, square it, add them all together, and divide by 6.

The result is not exactly 2.903.