Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Simulate Dice Sum Probability

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Simulate Dice Sum Probability. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A simulation has already rolled two fair six-sided dice for you, once per trial. You are given the outcomes as a list rolls, where each element is a two-element list [die1, die2] and each die value is an integer from 1 to 6.

Write a Python function that returns the empirical probability that the sum of the two dice is 7: the fraction of rolls whose values sum to 7, returned as a floating-point number.

Constraints

  • 1 <= len(rolls) <= 10^7
  • Each roll is a list [die1, die2] with 1 <= die1, die2 <= 6
  • The function returns a floating-point value in the range [0, 1]

Function Signature

def empirical_probability_sum_seven(rolls):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output