calculate the value of pi by throwing darts. We will create two shapes, a square and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
calculate the value of pi by throwing darts. We will create two shapes, a square and a circle inscribed in that square, as shown below. The radius of the circle is 1, so the length of each side of the square is 2. If we throw darts such that they all land in the square and are evenly distributed about the square, then the proportion of darts that land in the circle to the number of darts thrown is darts in circle darts thrown We can calculate the area of the circle as Area = into the equation above and solve for it, we get * = r = 1 darts in circle darts thrown area of circle area of square r² = and the area of the square is 4. We plug * area of square If we limit our area of concern to the upper right quadrant of the square, the area of the square is reduced to 1, and the area of the circle is */4, so the equation doesn't change, but we only have to throw darts in between 0<x< 1 and 0 <y<1. Write Python code to solve the problem as stated. The program should calculate pi by throwing darts. The program shall have: 1. A loop of some type. Structures such as while true: and break are prohibited from use, and will result in a 0 on the project if used. 2. An if statement of some type. 3. A function that is useful, appropriate, and appropriately defined and called. All code should be properly commented, with the student's name as a comment at the top. Students shall list as comments everywhere they received help for the code. GETTING HELP FROM CHEGG.COM IS PROHIBITED. calculate the value of pi by throwing darts. We will create two shapes, a square and a circle inscribed in that square, as shown below. The radius of the circle is 1, so the length of each side of the square is 2. If we throw darts such that they all land in the square and are evenly distributed about the square, then the proportion of darts that land in the circle to the number of darts thrown is darts in circle darts thrown We can calculate the area of the circle as Area = into the equation above and solve for it, we get * = r = 1 darts in circle darts thrown area of circle area of square r² = and the area of the square is 4. We plug * area of square If we limit our area of concern to the upper right quadrant of the square, the area of the square is reduced to 1, and the area of the circle is */4, so the equation doesn't change, but we only have to throw darts in between 0<x< 1 and 0 <y<1. Write Python code to solve the problem as stated. The program should calculate pi by throwing darts. The program shall have: 1. A loop of some type. Structures such as while true: and break are prohibited from use, and will result in a 0 on the project if used. 2. An if statement of some type. 3. A function that is useful, appropriate, and appropriately defined and called. All code should be properly commented, with the student's name as a comment at the top. Students shall list as comments everywhere they received help for the code. GETTING HELP FROM CHEGG.COM IS PROHIBITED.
Expert Answer:
Answer rating: 100% (QA)
Step 1 of 1 Heres an implementation in Python that meets the requirements Import the random module for generating random numbers import random Define ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Complete this question by entering your answers in the tabs below. Req 1 Req 2 Req 3A and 3B Req 4 For Year 2, prepare a direct labor budget for each month of April, May, and June. (Enter your direct...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
In several of the above exercises, we have indicated that an infinite series 1/(1+r )+1/(1+r )2 +1/(1+r )3 +... sums to 1/r . This can (and has, in some of the B-parts of exercises above) been used...
-
If accounting-based performance measures, such as net income or core earnings, are to be significant components of manager compensation plans, they need to be sensitive and precise measures of...
-
What kind of Zeeman Effect normal or anomalous, is observed in a weak magnetic field in the case of spectral lines caused by the following transitions: (a) 1P 1S; (b) 2D5/2 2P3/2; (c) 3D1 3Po; (d)...
-
17. What is meant when a persons mass is stated as 73.6 kg? That A. the mass is closer to 73.6 than it is to 73.7 or 73.5 B. the mass is closer to 73.6 than to any other value C. the mass is between...
-
Would the critical Rayleigh number for flow transition for the Bnard problem increase or decrease with the Prandtl number? Explain why in terms of the physics of the problem.
-
1. Prepare an outline of the benefits that DH might expect to obtain from this CRM project. Use categories to organize your list of benefits; for example, you might identify benefits that will accrue...
-
Create a Assignment: Implementing Lean Operations Assume that you are a manager at a small coffee shop or a McDonald's fast-food restaurant. Your task is to implement lean operations to improve...
-
The propeller in Prob. 9.1 is replaced with a six-blade turbine 400 mm in diameter, and the fluid to be agitated is a pseudoplastic power law liquid having an apparent viscosity of 15 P when the...
-
What is a key difference between binomial and Poisson distributions? The binomial distribution deals with discrete data; Poisson is a continuous distribution. The binomial distribution is a...
-
Which of the following rules about a default branch in a switch statement are correct? (Choose two.) A. A switch statement is required to declare a default statement. B. A default statement must be...
-
What is output by the following? A. 3 10 B. 3 12 C. 5 10 D. 5 12 E. The code does not compile. F. None of the above. 10: int m = 0, n = 0; 11: while (m < 5) { 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:...
-
Assume there is a class Bouncer with a protected variable. Methods in which class can access this variable? A. Any subclass of Bouncer or any class in the same package as Bouncer B. Any superclass of...
-
Variables declared as which of the following are never permitted in a switch statement? (Choose two.) A. var B. double C. int D. String E. char F. Object
-
Given the following enum and class, which option fills in the blank and allows the code to compile? enum Season { SPRING, SUMMER, WINTER } public class Weather { } public int getAverage Temperate...
-
15 1.39 points Decentraland Inc. stock provided a return of 2%, 12% and 22% returns in the past three years. What was the standard deviation of these returrns? 10,98% 11.05% 11.01% 000 10.99% 11.00%...
-
What are the risks and liability factors in an audit? What are the implications to the auditor? What are the implications to the organization? How can the auditor mitigate these risks and liability...
-
In Exercises, find the open intervals where the functions are concave upward or concave downward. Find any inflection points. (x) = x 8/3 - 4x 5/3
-
By properties of logarithms, Use this to find a Taylor series for ln [(1 + x)/(1 - x)]. In " (1+x)_ = - In(1 + x) ln(1 x). -
-
Describe what a total differential is and how it is useful.
-
In the research on leader behaviors, which style of leadership describes the preferred high-high combination? (a) transformational (b) transactional (c) laissez-faire (d) democratic
-
When managers use offers of rewards and threats of punishments to try to get others to do what they want them to do, they are using which type of power? (a) formal authority (b) position (c) referent...
-
In terms of leadership behaviors, someone who focuses on doing a very good job of planning work tasks, setting performance standards, and monitoring results would be described as _________. (a) task...
Study smarter with the SolutionInn App