Write a Python programs to do frequency counting of the sum of two dice. Your function should accept an integer nn parameter to run nn trials (i.e., multiple rollings of the two dice); You can use the Python function randrange(1, 7) to simulate the roll of one die; After running the nn trials, your function should return the sum of two dice that occurs most frequently. Please implement the following: sim_dice(n) Estimate the most probable sum of rolling two regular 6-faced dice repeatedly, using frequency counting. The function definition has already been started, below. It has one parameter, the number of rolls to perform on the two dice that you will frequency count. The return value will be the most common sum, and the frequency of that sum (e.g. the dice sum of 7 happens 142 times). main() The only purpose of this function is to call sim_dice(1000) and print the returned value of the most frequently occurring sum. You are required to use this starter code as part of your solution: from random import randrange def sim_dice(n): # The sum of two dice range from minimum of 2 to a maximum of 12. # Use this list to store the frequency of these sums freqs = [-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] _max = 0 # Store the sum of two dice the occurs most often.
Write a Python programs to do frequency counting of the sum of two dice.
-
Your function should accept an integer nn parameter to run nn trials (i.e., multiple rollings of the two dice);
-
You can use the Python function randrange(1, 7) to simulate the roll of one die;
-
After running the nn trials, your function should return the sum of two dice that occurs most frequently.
Please implement the following:
-
sim_dice(n)
Estimate the most probable sum of rolling two regular 6-faced dice repeatedly, using frequency counting. The function definition has already been started, below. It has one parameter, the number of rolls to perform on the two dice that you will frequency count. The return value will be the most common sum, and the frequency of that sum (e.g. the dice sum of 7 happens 142 times).
-
main()
The only purpose of this function is to call sim_dice(1000) and print the returned value of the most frequently occurring sum.
You are required to use this starter code as part of your solution:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images