Write a python simulation to experimentally verify problem

Assignment Help Python Programming
Reference no: EM132104939

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.

Reference no: EM132104939

Questions Cloud

What is the size of the banks actual reserve : If a bank has access reserves of $8000 and checkable deposits of $150000. If the reserve ratio is 20% what is the size of the banks actual reserve?
Describe how use of the net present value technique : Describe how use of the net present value technique would assist the company in coming up with the best investment decision.
Implement the lexical analysis task : Your C++ code should input a text ?le from user, which contains the expressionhe/she wants the compilers to analyze.
Design a structure in c that contains data to model a state : Design a structure in C that contains data to model a state capital and write several functions that process and act on that data.
Write a python simulation to experimentally verify problem : Write a Python simulation to experimentally verify the Monty Hall problem. Your simulation should run a large number of trials for two scenarios.
Why pathology collector should follow communication protocol : CHCCOM005 Communicate and Work in Health or Community Services -HLT37215 Certificate III in Pathology Collection - Why is it important for you to listen
Assign the cost of the copy center to department : How would you assign the cost of the copy center to each department? Why?
How do you prepare flexible expense budget that reflects : How do you prepare flexible expense budget that reflects what each expense should have been for 2016 in the Bellaire Clinical Lab?
Variable overhead rate : The predetermined overhead rate for Zane Company is $5, comprised of a variable overhead rate of $3 and a fixed rate of $2. The amount of budgeted overhead cost

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd