Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Simulate Dice Sum Probability

EasyPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Simulate Dice Sum Probability. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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

Problem

Write a Python function that simulates rolling two fair six-sided dice for a given number of trials and returns the empirical probability that the sum of the two dice is 7. The function should take an integer trials as input and return a floating-point probability.

Constraints

  • 1 <= trials <= 10^7
  • Each die roll is an integer from 1 to 6 chosen uniformly at random
  • The function returns a floating-point value in the range [0, 1]

Function Signature

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