Question: IT IS FOR PYTHON QUESTION, I NEED HELP Swiss cheese is a type of cheese that typically has a bunch of holes in it. For
IT IS FOR PYTHON QUESTION, I NEED HELP
Swiss cheese is a type of cheese that typically has a bunch of holes in it. For this question, you will write a program that draws an orange block (the cheese) with some number of holes at random locations all over its surface. This program is non-interactive, so you wont need functions like setup() or draw(). Your programs output will just be a still image of the cheese. Figure 1: A block of swiss cheese with 15 holes in it. Here are the specications for this problem: Use a 300x300 canvas. Usually the canvas size is pretty arbitrary, but this time it will be important to demonstrate your understanding of this problem. Draw the block of cheese with its top left corner at (50, 50) and with a width and height of 200. Use a while-loop to draw N small black holes (circles of diameter 20) on the cheese. The example above uses N of 15, but your program should work for any value of N. It is okay if the circles sometimes overlap with each other, but they should all be completely on the cheese. Heres the trick: your holes in the cheese need to be at random locations. To generate random coordinates for a single hole, use these two lines of code: x = int( random (0 , 300)) y = int( random (0 , 300)) The random() function simply returns a random number within the specied bounds, so in this case, x and y will be random coordinates on your 300x300 canvas. The problem is that the cheese doesnt ll the whole canvas, so sometimes the random coordinates will be no good. That simply means youll have to not draw a rectangle at those coordinates and try again. Thats why you need to use a while-loop for this problem, because you dont know how long it will take to generate valid coordinates for N holes in the cheese 1 Hint: Make sure to take the diameter/radius of the holes into account when checking if the random coordinates are valid; your holes need to be *completely* on the cheese!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
