Video Tutorial: Python Functions with Turtle Graphics
As 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.
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:
The tutorial is in 5 stages as follows:
- Create separate functions to draw a square and a triangle
- Combing two functions into one by passing values to the function.
- Pass a second value to the function
- Using algorithmic thinking to simplify our code and make it more flexible
- Using constants to make our code more readable and modifiable
Recent blog posts
- Simple Python Game Tutorial Using Classes
- Video Tutorial: Python Spacewar Game
- Video Tutorial: Python To-Do-List (GUI Version)
- Video Tutorial: Simple Space Invaders Clone
- Video Tutorial: Python Functions with Turtle Graphics
- Video Tutorial: Python Guessing Game (GUI Version)
- Global Codeathon Scratch Tutorials
- Video Tutorial: A Simple Python Turtle Graphics Game
- Video Tutorial: Tic-Tac-Toe in Python
- In Favor of Standardization in Ed Tech