Session Ready
Exercise

Throw a dice

Let's create an infinite generator! Your task is to define the simulate_dice_throws() generator. It generates the outcomes of a 6-sided dice tosses in the form of a dictionary out. Each key is a possible outcome (1, 2, 3, 4, 5, 6). Each value is a list: the first value is the amount of realizations of an outcome and the second, the ratio of realizations to the total number of tosses total.

Tip: use the randint() function from the random module (already imported). It generates a random integer in the specified interval (e.g. randint(1, 2) can be 1 or 2).

Instructions
100 XP
  • Simulate a single toss to get a new number.
  • Update the number and the ratio of realization.
  • Yield the updated dictionary.
  • Create the generator and simulate 1000 tosses.