Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

One of your friends wonders out loud how probable it would to hit a colored section of the painting if they were to close their

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

One of your friends wonders out loud how probable it would to hit a colored section of the painting if they were to close their eyes and throw a dart at random at the canvas. You tell your friend that this is a very bad idea, but because you are in an Introduction to Computer Programming class you know that you can use your newly acquired Python skills to solve this problem! For this program you will be writing some code that will simulate the throwing of a random dart at this modern art 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 playing field is 800 units wide and 500 units high, so you will be generating random 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 schematic below for the exact measurements of the painting. Hint: Start off by simulating just one dart toss and use the coordinate plane to determine if the dart has fallen into one of the colored regions. Start off with the red rectangle since it will be the simplest shape to work with -- how 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 may need the distance formula again to determine if a point falls within a circular region! Once you are confident that you have designed an effective algorithm you can scale up and place your code inside a loop. 0,0 Q00 (1) (3) 50 Q.0.0 500 Canvas is 800 units wide by 500 units high Origin point (0,0) is at the top left edge of the diagram Here's a a few sample runnings of the program with user input highlighted: Input assumptions: - Number of throws: a value of data type 'integer' within the range -2147483648 to 2147483647 Some hints: - You can always assume the user will enter an integer when prompted, but you will need to validate it so that it falls within the desired range (1 or larger) - Start off by generating a single random point within the bounds of the painting (an x value between 0 and 800 and a y value between 0 and 500 ). The coordinate system shown here is one that is standard in the world of computer graphics -- notice that the origin point is at the top left side of the screen, and that the y axis only contains positive values. - Next, write a series of tests to see if the number you just picked falls within one of the shapes shown. If so, you should update an accumulator to go count this as a "hit" to that particular region. - The distance formula may be helpful in determining if a point falls within a circle (hint: if the distance from a point to the center of a circle is less than the radius of that circle then the point can be considered inside of that circle. - Once this works for a single point you will need to design a loop to iterate a large number of times and repeat this process. We sometimes call this a 'Monte Carlo' simulation, which is designed to approximate a solution to a problem through the use of random numbers. - Because of this you will see different numbers when you run your program. The percentages that get generates should roughly match the percentages shown here. They will not be exactly the same unless your program generates the exact same random numbers as mine, and you generate those values in the same order as my program. It's not required to get exactly the same answer for this program as long as your values are close to the sample outputs

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

| Who are people who model the values that I want to live?

Answered: 1 week ago

Question

| In what ways am 1 striving to make their lives better?

Answered: 1 week ago