Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with python code Show all work and steps Thanks In the development of probability theory that underpins much of statistics, the roll of

Need help with python code
Show all work and steps
Thanks
image text in transcribed
In the development of probability theory that underpins much of statistics, the roll of a "fair die" 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 die and an un-fair die. 1. Create a Python file called Die.py in PyCharm. 2. Create a function called rold FairDie () 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 01 into six equal pieces like: x - random () if (x>1.0/6) : return 1 else if (x2.0/6): etc. return 2 3. In a separate file called HW1SP23 Prob1.py: a. Import the module Die b. Write and call a main() function that calls rol1FairDie () 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: After rolling the die 1000 times: Probability of ro11ing a 1 : 0.1667 Probability of rolling a 2:0.1668 Etc. 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 rol1FairDie () 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: After rolling the die 10,000 times: Probability of rolling a 1:0.1667 Probability of rolling a 2: 0.1668 Etc. 4. Modify your Die.py file to include a function called rollunFairdie() where the die has been modified to roll a 1 with a probability of 0.2. Write and call a main3 () function that calls the ro11UnFairDie() 10000 times and outputs the results as in step 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions