Ask Python Expert

This problem deals with continuous (rather than discrete) probability, but it's an interesting problem! It involves probabilistically estimating the value of (pie). Consider a circle of radius 1 inscribed within a square with side 2. Both shapes are centered at the origin (0, 0).

Using basic geometry, the ratio of the circle's area to the square's area is(pie) (1)2/22 = (pie)/4.

Now, suppose that you randomly throw some darts at this figure. Out of n total attempts, m attempts land within the circle. As the number of attempts becomes large, the ratio m/n should approach the ratio of the circle's area to the square's area. Thus, we can write (pie)/4 = m/n. Solving for(pie) gives us (pie) = 4m/n.

Write a Python program that allows the user to enter a value for n (the total number of attempts). Your program should then simulate throwing n darts at the figure by randomly picking coordinates (x, y) between -1.0 and 1.0. Keep track of the darts that land within the circle, and show the resulting estimate for(pie) .

Python hint: Python's random() function (located in the random module) behaves the same as Java's Math.random() - it returns a uniformly distributed pseudorandom real number in the interval [0.0, 1.0). To call it:

import random
x = random.random()

2. The Monty Hall problem is a counterintuitive example of how probability works. Here's the premise: You are on a game show where you have to pick one of three closed doors. Behind one of these doors is a new car, and behind the other two are goats. Once you've picked a door, the show's host (who knows the winning door) opens one of the other doors to reveal a goat and asks if you'd like to change your choice. To maximize your chances of winning the car, should you change or stay with your original door?

The probability that you originally picked the winning door is obviously 1/3. This means that the probability you originally picked a losing door is 2/3. However, if you originally picked a losing door and change your choice after the host opens the other losing door, you are guaranteed a win!

(Remember that the door opened by the host is always a losing door.) Thus, if you always change your choice, the probability that you win is the same as the probability that you initially picked
a losing door. This is 2/3 - much better than sticking with your original choice!

(Of course, all this analysis does assume that you'd prefer a new car over a goat...)

Write a Python simulation to experimentally verify the Monty Hall problem. Your simulation should run a large number of trials for two scenarios: staying with the original door, and changing the door. For each scenario, report the number and percentage of wins over all of the trials.

Simulation algorithm (for each trial) for staying with the original door:

a. Randomly place the car

b. Have the player randomly choose one of the three doors

c. Determine whether the player won

Note that the above scenario does not require accounting for which door is opened, since the player is not going to alter his/her original choice.

Simulation algorithm (for each trial) for changing the door:

d. Randomly place the car

e. Have the player randomly choose one of the three doors

f. Open a losing door (besides the player's original choice)

g. Change the player's choice to the one remaining door

h. Determine whether the player won

Python hint: Python's randint(a, b) function (also located in the random module) returns a random integer N such that a (less than or equal to) N (less than or equal to) b.

Python, Programming

  • Category:- Python
  • Reference No.:- M93092408

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

Tasksdemonstrate data scraping of a social network of

Tasks Demonstrate data scraping of a social network of choice. Develop technical documentation, including the development of the code & detailing the results. Provide a report on the findings, that includes research into ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

Python programming assignment -you first need an abstract

Python Programming Assignment - You first need an abstract base class, called, Account which has the following attributes and methods: accountID: This attribute holds the ID assigned the account , if not provided set to ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Question research pythons dictionary data type dictdiscuss

Question : Research Python's dictionary data type (dict). Discuss its interface and usage. Include examples. Discuss practical applications of dictionaries.

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

Below zero - ice cream storethe local ice-cream store needs

Below Zero - ice cream store The local ice-cream store needs a new ordering system to improve customer service by streamlining the ordering process. The manager of the store has found that many orders are incorrect and s ...

The second task in this assignment is to create a python

The second task in this assignment is to create a Python program called pancakes.py that will determine the final order of a stack of pancakes after a series of flips.(PYTHON 3) Problem Task In this problem, your input w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As