Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hover over each shape for tool tips with color information For this program you will be writing code that simulates throwing a dart randomly at

Hover over each shape for tool tips with color information
For this program you will be writing code that simulates throwing a dart randomly at the painting. To do this, you can repeatedly generate a random coordinate within the painting area and test to see which shape (if any) the dart falls into. Note that the two-dimensional plane is 800 units wide \times 500 units high and origin point (0,0) is at the top left corner, so you will be generating coordinates within this range as part of your simulation. When you are finished you should calculate the % chance of a dart hitting a particular shape.
Refer to the diagram below for the exact measurements of the painting and locations of shapes. As youre getting started, simulate just one dart toss and use the coordinate plane to determine if the dart has fallen into one of the colored regions. Begin with the red rectangle since it will be the simplest shape to work withhow can you write a statement to determine if a point falls within a rectangle?
From there, expand this logic and apply it to the other shapes. Hint: you can use the distance formula from assignment 3 again to determine if a point falls within a circular region. Once you are confident that youve designed an effective algorithm, you can scale up and place your code inside a count-controlled loop.
Here are two examples of the program running followed by some additional tips.
How many dart throws? 10000
Green: 1,296(12.96%)
Yellow: 1,695(16.95%)
Red: 1,010(10.10%)
Gray: 623(6.23%)
Blue: 657(6.57%)
Black: 107(1.07%)
Miss: 4,612(46.12%)
How many dart throws? -1000
Please enter a positive number: 0
Please enter a positive number: 50000
Green: 6,277(12.55%)
Yellow: 8,845(17.69%)
Red: 5,064(10.13%)
Gray: 3,388(6.78%)
Blue: 3,432(6.86%)
Black: 570(1.14%)
Miss: 22,424(44.85%)
This simulation approximates a solution to a problem; because of this, you will see different numbers when you run your program. The percentages that are generated should roughly match the percentages shown here. The more dart throws you compute the closer you will get to the actual solution.
You can generate a random floating point number within a given range by using the random modules uniform() function. This function takes two argumentsa low boundary and a high boundaryand generates a floating point number within this range (edges inclusive).
The coordinate system shown here is one that is standard in the world of computer graphics. Notice that the origin point (0,0) is at the top left corner of the plane and that the x and y axes involve positive values.
You will need to validate input (to ensure your program works with positive numbers) and format the output with commas for thousands and two decimal places for percentages.
8
image text in transcribed

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions