# C3_W2_Exersice 1

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?

What results do you get?

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

The notes in the notebook says Exercise 1 is not a graded part of the assignment.

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

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.

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.