Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is for Python 2.7: To simulate the Buffon needle experiment, you will need to generate two random numbers: one random number to describe where
This is for Python 2.7:
To simulate the Buffon needle experiment, you will need to generate two random numbers: one random number to describe where the tail of the needle landed on the y-axis and another to describe the angle of the needle with respect to the x-axis. A random floating point number between 0 and 1.0 can be generated using the function random(), which you need to import from the Python module also named random. So, at the top of your python program you will need the following code: from random import random Which says to import the function random() from the random module. You could then, for example, generate a random number between 0 and 100 with the following code: from random import random some_float-between_0_and_100 = 100.0* random() print some_float_between_0_and_100 For this experiment, you may generate the coordinate of where the tail of the needle landed tail as a number between 0 and 2.0. Likewise, the angle theta the needle makes with respect to the x-axis will randomly be something between 0 and pi radians. The head of the needle head may then be computed as: y_head = y_tail + sin(theta) If the head of the needle react is greater than 2.0, you count that simulated attempt as a hit. Likewise, if y_head is less than 2.0, do not count that attempt as a hit. The trigonometric function sin() is available from the math module, as is the numerical constant pi. You can import these for use in your program by adding the following statement to the top of your Python program: from math import pi, sin # Some simple demonstration print pi print sin (pi/2.0) Your program should prompt the user for the number of attempts to perform (i.e., how many times we will simulate dropping the needle) and print the ratio attempts hits as a floating point number after all the attempts have completedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started