Question: Write a program (start fresh) that draws a square (make it at least 500 pixels wide/high). Center the box in your screen. Inside the
Write a program (start fresh) that draws a square (make it at least 500 pixels wide/high). Center the box in your screen. Inside the box, you will draw a lawn. This is not to be just a rectangular block of green. You will need to draw every blade of grass (use a pen width no greater than 3). The blade lengths should be random (choose values that will make it look "realistic"). The shade of green should also be random. You will utilize variables that change values within a loop (moving your pen for each new blade of grass), random numbers (for the grass blade length and shade of green), and other concepts from this lab and prior labs. See the example below. (View it on Blackboard to see in color.) Once this works, move on to the next part of this task. Next, add code to your program that keeps track of how many of each different length blade was drawn. For example, my random range for the grass blade length was between 15 and 23 pixels. I'm interested in knowing how many times 15 was generated, how many times 16 was generated, how many times 17 was generated, etc. This will require several variables that you set up as counters. Keep track of each length usingif/eli/else statements inside your loop. (Be careful with indentation!) Once the grass is completely done, print all of your values to the IDLE shell. Be sure to include a label. When I run mine, it appears as shown on the next page. A small snippet of code is also included as a hint. 15 pixels: 22 16 pixels: 21 17 pixels: 21 18 pixels: 24 19 pixels: 18 20 pixels: 32 21 pixels: 21 22 pixels: 24 23 pixels: 18 >>> |
Step by Step Solution
3.41 Rating (157 Votes )
There are 3 Steps involved in it
To create a Python program that draws a square with blades of grass inside and keeps track of the di... View full answer
Get step-by-step solutions from verified subject matter experts
