In the development of probability theory that underpins much of statistics, the roll of a fair pie
Fantastic news! We've Found the answer you've been seeking!
Question:
- In the development of probability theory that underpins much of statistics, the roll of a "fair pie" is often cited as a key concept. We want to write a simple program that utilizes a random number generator to mimic the behavior of a fair pie and an unfair pie.
- To Do:
- 1. Create a Python file called Pie.py in PyCharm.
- 2. Create a function called rollFairPie() that takes no arguments and returns an integer between 1 and 6 inclusively but at random each time the function is called.
- a. You must import the module random and call the function random() to produce a floating point number between 0.0 and 1.0.
- b. Convert the floating point number to an integer (1-6) with equal probability by dividing the range 0-1 into six equal bins and using an if-then structure to return the appropriate integer. For example, we might break the range between 0-1 into six equal pieces like:
- x = random()
- if (x/6.0 ≤ 1.0/6)
- return 1
- else if (x/6.0 ≤ 2.0/6)
- return 2
- etc.
- 3. In a separate file called HW1SP21_Prob1.py:
- a. Import the module Pie
- b. Write and call a main() function that calls rollFairPie() 1000 times and computes the fraction of rolls that yield 1, 2, 3, etc.
- c. Output the probability of each of the possible numbers to the screen as formatted text:
|
- d. Do these probabilities match the theory? Calculate the probabilities if we roll the die 10,000 times by writing and calling a main2() function that calls rollFairPie() 10,000 times and computes the fraction of rolls that yield 1, 2, 3, etc.
- e. Output the probability of each of the possible numbers to the screen as formatted text:
|
- 4. Modify your Pie.py file to include a function called rollUnFairPie() where the pie has been modified to roll a 1 with a probability of 0.2. Write and call a main3() function that calls the rollUnfairPie() 10000 times and outputs the results as in step 3.
Related Book For
Managerial Accounting An Integrative Approach
ISBN: 9780999500491
2nd Edition
Authors: C J Mcnair Connoly, Kenneth Merchant
Posted Date: