When creating a post, please add:

- Week # 2.
- Link to the classroom item you are referring to: here
- Description (include relevant info but please do not post solution code or your entire notebook)

## Exercise 7:

Given a 6-sided fair dice you try a new game. You only throw the dice a second time if the result of the first throw is **lower** or equal to 3. Which of the following `probability mass functions`

will be the one you should get given this new constraint?

Hints:

- You can simulate the second throws as a numpy array and then make the values that met a certain criteria equal to 0 by using np.where

## My solution code:

*{moderator edit - solution code removed}*

## Actual Output

## Expected answer

Correct Coursera answer was supposed to be right-center. Can anyone explain how does this work?

Hi @abdallahheidar!

Please do not include the solution code in your post as stated in the guideline: â€śinclude relevant info but please do not post solution code or your entire notebookâ€ť.

On my end, it seems like the expected answer should be the left-center graph, the one in blue.

Keep in mind that if the first throw is greater than 3, we do not throw the die a second time, but we still keep the sum of just the first throwâ€™s value. So you donâ€™t want to apply the filter to include the first throw when they are only <= 3. Instead, you want to apply the filter on the second throws, on the condition of the first throw being <= 3, since we only throw the die a second time when that condition is true.

To explain the expected answer, we can count up the possible sums of the throws.

- If the first throw is 1, there are 6 possibilities for the second throw: 1, 2, 3, 4, 5, or 6
- If the first throw is 2, there are 6 possibilities for the second throw: 1, 2, 3, 4, 5, or 6
- If the first throw is 3, there are 6 possibilities for the second throw: 1, 2, 3, 4, 5, or 6
- If the first throw is 4, 5 or 6, we do not throw the die a second time.

As a result, all the possible sums are:

- when first throw is 1, possible sums: 2, 3, 4, 5, 6, 7
- when first throw is 2, possible sums: 3, 4, 5, 6, 7, 8
- when first throw is 3, possible sums: 4, 5, 6, 7, 8, 9
- when first throw is 4, possible sums: 4
- when first throw is 5, possible sums: 5
- when first throw is 6, possible sums: 6

The counts for each sum are then:

sum of 2: 1

sum of 3: 2

sum of 4: 4

sum of 5: 4

sum of 6: 4

sum of 7: 3

sum of 8: 2

sum of 9: 1

Based on this outcome, the closest graph would be the left-center one.

I hope this helps!

2 Likes

Thanks for the reply, I changed the logic according to your instructions and got this output. Does it match yours?

Hi @abdallahheidar, glad I could help.

Yes, I think thatâ€™s looking closer to the expected output. Good job!

I noticed there are only 7 bars in your plot, but there should be 8, one for each possible sum.

In order to get the expected plot, I would suggest referring back to the notebook for the Lab â€śSimulating Dice Rolls with Numpyâ€ť. The notebook should have some calls to `sns.histplot()`

which you can try to follow using the same parameter values, such as `discrete`

.

Best of luck!

2 Likes