Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can expert explain this step by step code please? Problem 1: A game of chance, rolling a single die In the development of probability theory

Can expert explain this step by step code please?

image text in transcribed

Problem 1: A game of chance, rolling a single die 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. To Do: 1. Create a Python file called Die.py in PyCharm. 2. Create a function called rollFairDie () 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/6.01.0/6) return 1 else if (x/6.02.0/6) return 2 etc. 3. In a separate file called HW1SP23_Prob1.py: a. Import the module Die b. Write and call a main () function that calls rollFairDie () 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 rolling 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 rollFairDie () 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 rollunfairdie () 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 to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

Selectively increase group and team structure.

Answered: 1 week ago