Video Tutorial: Python Functions with Turtle Graphics

Turtle GraphicsAs you learn more about coding, you will find that you will be using and reusing code.  Rather than writing the code out again and again and again, you can create functions.  The Webopedia defines a function as "a named section of a program that performs a specific task." 

Functions are used for two main reasons: reusability and abstraction. Reusability means you can use the code in many different programs, so once you create a function, you can use it in other contexts.  Also, abstraction means that you don't have to know how a function works to use it in your program - thus one coder can use the work of another without knowing all the details of the implementation.

The Program

We will be making a simple program that draws a number of shapes on the screen in different colors.  To draw the shapes, we will create one simple function that can be used to draw any number of different polygons.  Here is what your finished output will look like:

Sample Output

The Tutorial

The tutorial is in 5 stages as follows:

STAGE I: VIDEO / CODE

  • Create separate functions to draw a square and a triangle

STAGE II: VIDEO / CODE

  • Combing two functions into one by passing values to the function.

STAGE III: VIDEO / CODE

  • Pass a second value to the function

STAGE IV: VIDEO / CODE

  • Using algorithmic thinking to simplify our code and make it more flexible

STAGE V: VIDEO / CODE

  • Using constants to make our code more readable and modifiable

I hope you find this useful.  If so, please comment on the YouTube videos, subscribe to my YouTube channel, and follow me on Twitter (@tokyoedtech)

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.

@TokyoEdTech

Poll

What LMS does your school use?: