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.
Page 1: Intro
Page 2: The theory: learn what you need to know as fast as possible.
Page 3: Try it: try out and adapt some working python code snippets.
Page 4: Debug it: Learn how to find and fix common mistakes.
Page 5: Extend it: Choose a project idea to use your newfound python skills.