8.8. Chapter Exercises¶
The code currently draws a square. Change it so that it draws a triangle.
Fix the errors in the code so that it draws an octagon.
Fix the indention in the code below to correctly draw 20 pentagons (5 sided polygons).
Make sure to use four spaces for each indentation level (the tab key will automatically use 4 spaces).
- range(10, 0, -2)
- Correct
- range(10, 1, 2)
- That counts up by 2's
- range(10, 2, -2)
- That recipe would not generate 2 because it is the stop value
- range(10, 3, 2)
- This recipe counts up by 2's
Which is range recipe would generate the sequence: 10, 8, 6, … 2
Write the correct recipe to fill in the ____________ in the code below to generate the pattern 5, 25, 45, … 105. Use the smallest possible value for your stopValue. (Don’t include “range” or the parentheses in your answer; do include commas).
range(____________)
We want to make a series of rectangles such that the first one is 10x90, the next is 20x80, the next is 30x70, … until we draw one that is 90x10. Doing so will make a “staircase grid” like the one shown below:
Below is a program with rectangle
already defined. Add code that uses a for
loop to call the procedure with the correct values for its parameters. Make sure
that the 90 width and 10 height rectangle is the first one you draw. You should
only need one loop - it must count down from 90 to 10.
Hint: The values we use for width and height will always add to 100. So if we call one of them \(w\), the other must be \(100 - w\).
The autograder will not verify everything about your program. It is up to you to determine if your program is correct or not.