Log out reminder
Once you have written the code, you need to verify your answers. You can do this by running the code and checking the output. The probabilities should be close to the theoretical values:
def roll_die(): roll = random.randint(1, 6) return roll
Here's an updated code snippet:
Are you struggling to complete the 4.3.5 Rolling Dice assignment on CodeHS? Look no further! This article provides a detailed guide to help you understand the problem, write the code, and verify your answers.
def probability_sum_2(): """Calculates the probability of rolling a sum of 2 with two dice""" count = 0 total = 0 for _ in range(10000): die1, die2 = roll_two_dice() if die1 + die2 == 2: count += 1 total += 1 return count / total