Below you’ll see some python code which will draw some coloured shapes :
Ctrl + Enter to run the code.
Here’s how the code works:
Lines 6-10 defines a procedure called
draw_shape which has two parameters:
sides: how many sides the shape has, e.g. 4 for a square
size: the length of each side in pixels
Lines 12 – 16 defines a procedures called
fill_shape. This calls draw_shape on
line 15 passing on the values of the parameters
shape but it also has another parameter for the
colour of the shape
Lines 19 and 22 call the procedure
fill_shape to draw a square and triangle
Start by running the code.
- Change the size of the red square to
You will need to change the value of the second parameter on line 19
- Draw a
5sided shape (pentagon) size
You’ll need to call
fill_shapeagain with your own values for
sides, `size` and
- Draw a
Apparently a 32 sided shape is a triacontadigon. Yes, I had to look that up. But it looks pretty much like a circle to me when it’s that small.
On the next page you’ll get some code with both syntax and logic errors
KPRIDE stands for Keywords, Predict, Run, Investigate, Debug and Extend and it’s a way of helping you explore and understand python code. Click on the image below for a set of KPRIDE activities for this python skill.