16: Procedures in python

Try it:

Reuse sections of your code
Procedures in python: Reuse sections of your code

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:

Press Ctrl + Enter  to run the code.

Challenges:

Start by running the code.

  1. 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 0 then the turtle will draw as fast as it possibly can.

  2. Make it display 20 squares instead of 10

    There is a constant called SHAPES which you’ll need to change on line 7

  3. 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

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.

2 thoughts on “16: Procedures in python

  • November 22, 2020 at 4:47 pm
    Permalink

    Hi there,

    Absolutely love your resources on programming and started using them today. Just wondering if there are solutions for the de-bugs on the programs here that pupils are supposed to de-bug. It will help me a lot so I can compare their answers with it.

    Reply
    • November 24, 2020 at 11:40 am
      Permalink

      Hello,
      Thanks so much for your message. I haven’t written up the answers yet – I’m trying go get through the full set of 20 activities then the next job will be to publish a student workbook and set of answers. Sorry not to help yet. Hope you’re well

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *