# Week 8: Exercise Solutions

## Exercise 8.1

```import random
random.seed()

NO_OF_TRIALS = 1000000

frequency =  * 13

for i in range(NO_OF_TRIALS):
dice_score = random.randrange(1, 7) + random.randrange(1, 7)
frequency[dice_score] = frequency[dice_score] + 1

print("score\trelative frequency")
print("-" * 26)
for i in range(2, 13):
print(i, "*" * int(100*frequency[i] / NO_OF_TRIALS), sep="\t")
```

With two dice there are 36 possible outcomes. We can represent an outcome by an ordered pair (a, b) where a is the score on the first dice and b is the score on the second.

• You can score a 2 only by rolling (1, 1) so the probability is 1/36 ≈ 0.0278.
• You can score a 3 by rolling (2, 1) or (1, 2), so the probability is 2/36 ≈ 0.556.
• You can score a 4 by rolling (3, 1), (2, 2), or (1, 3), so the probability is 3/36 ≈ 0.0833.

## Exercise 8.2

```import math

NO_OF_INTERVALS = 40

for i in range(NO_OF_INTERVALS + 1):
x = 2 * math.pi * i / NO_OF_INTERVALS
print(" " * int(30 * (1 + math.sin(x))) + "*")
```