Below you’ll see some example python code which asks the user to choose how large a square should be drawn. If the user doesn’t type in a number it will display a friendly message rather than crashing:
Ctrl + Enter to run the code.
Start by running the code.
- Change the speed to 0 so that the shapes are drawn faster
Line 5 will set the set the speed to 10 by calling the speed() procedure for the turtle graphics object
t.Bizarrely, if you set the speed to
0then the turtle will draw as fast as it possibly can.
- Make it display 20 squares instead of 10
There is a constant called
SHAPESwhich you’ll need to change on line 7
- Add pink to the list of possible square colours
There is a list called COLORS on line 8 which you can add additional colours into. Note the American spelling of colour when used in python.
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.