Answered step by step
Verified Expert Solution
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 twodimensional plane is units wide times units high and origin point 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 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 countcontrolled loop.
Here are two examples of the program running followed by some additional tips.
How many dart throws?
Green:
Yellow:
Red:
Gray:
Blue:
Black:
Miss:
How many dart throws?
Please enter a positive number:
Please enter a positive number:
Green:
Yellow:
Red:
Gray:
Blue:
Black:
Miss:
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 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.
Step 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