Happy Easter! Here is a lesson plan for a fun parent-child lesson; assuming no prior knowledge for both! It would be ideal if the parent could read over this lesson as they go along, making it immersive for their children.
Anyone who has a laptop and can type their name + use a mouse can do this lesson :)
Python is a programming language used for a diverse skill-set, it has influence over most technologies we use in our daily lives. It allows us to give a set of instructions to a system, much likes our computers, cellular towers, gaming consoles, etc. During the current COVID-19 pandemic, python is being widely used to give us real-time data about the number of cases, where they are, recovery rates, & more!
We are going to use Python, and Turtle. Turtle is a drawing board. So what will programming in Python allow us to do? It will allow us to the give the drawing board - turtle, a set of instructions and therefore control it!
The following lesson plan has words underlined which include key computer science, business, and mathematics concepts. Perhaps you want to discuss these further with your child! Steps where parents help is required are denoted by a "*". Questions that you can ask your child are marked with a bullet point. Answers are provided at the end of the blog.
Lesson Plan
1. Let's get started by opening the following link: https://repl.it/languages/python_turtle.
* It is recommended that you minimise this window and open the above link in another tab.
2. We are going to utilise the left-hand side (LHS) of the to give the computer instructions as a input, and the right-hand side (RHS) to see the output. It's quite similar to a vending machine, you give money (input) and receive a snack (output). But you have to tell the machine what snack you want and where it is located - similar to the computer!
So where will we do this? LHS or RHS?
Interpreter will output commands you provide along with displaying any errors in your code. If an error is spotted, it will specifically state the type and line number of error in your code.
LHS RHS
Interpreter
3. To use turtle ("drawing board") we need to tell the computer exactly what we want. Let us type the following in the LHS:
import turtle
When we import something, what do we do? The United Kingdom imports petrol from Norway. Basically, UK gets petrol from Norway (not for free of course!). We just imported the turtle feature to our computer. In programming, features that you can import are called libraries.
Can you come up with another example using the word, import? What about export?*
4. Let's change the colour of our background. But before we do that, we are going to name our screen. I am going to name mine "easter". Since the turtle is our drawing board, and it will be displayed on our screen - we will type:
easter = turtle.Screen()
Programming is a language, so every lowercase/capital or punctuation matters - it has it's own syntax just like english.
Now try giving your screen another name
5. How about blue for a background colour? If you used another name for your screen, type exactly that instead of "easter". Let us type the following in the LHS:
easter.bgcolor("blue")
Now click the "run" button on the top of the screen. This is telling the computer to run the instructions you have given it so far.
Your screen should now look like this:
Now try giving your screen another colour?
What does "bg" in bgcolor stand for?
6. You must be asking where is this turtle? How would you literally tell a turtle to move in a line? You would tell it the direction and how much (amount) you want it to walk. Let's say we want our turtle to move in the forward direction 100 units. 1 unit = 1 step. Type in LHS:
turtle.forward(100)
Click run and see what happens!
You might be wondering, the turtle went right not forward. Well, look at where the turtle head is pointed. So according to the turtle, it did move forward :)
Play around with values and see what happens!
7. Let's make the turtle turn left 100 steps now.
Can you draw how you think the screen will look?
Try typing the instruction yourself without look at the next step
8. The syntax* stays the same
turtle.left(100)
What happens when you click run?
The turtle did not go left 100 units! Well, I did say programming was a language. But it is its own language, to a turtle when using python - left something else!
*turtle.forward(100) moved the turtle forward by 100 units. turtle.left(100) turned the turtle left relative* to its position but did not make it move. In python when using the turtle library, left and right tell the turtle to turn a certain angle*. Angles are a form of direction, we are telling the turtle to turn certain amount of units instead of move.
When you are moving in a straight line and want to take a sharp left or right, you usually turn 90 degree. *Demonstrate this physically to your child.
9. We are now going to make a square. A square is a shape where all 4 sides are equal. Therefore, we need our turtle to move the same amount of units in all sides. Before we do that let us void* the last step. We do this by adding a hash (#) symbol before them.
Let us insert a hash symbol before our last line of code:
10. Now to make a square, we type the following:
The the output should be the following:
11. A square is fun, but 1 looks boring. Now computers are quite dumb without instructions, but can be very smart when told exactly what to do. Let's make our turtle smarter. We are going to make a function. If we want to make 4 squares, do we keep typing 8 lines of code repeatedly for each square?(That's 32 lines of code for 4 squares!) Well, we can - but there are smarter ways. A function allows us to define what we want the computer to do, in this case make a square. Then we can just call the function (1 line of code) instead of typing 8 lines of code each time.
Let's click enter on the end of line 3 and make an empty line for our function on line 4:
In line 4 let's type the following:
def draw_square:
"def" means definition. draw_square is the name of my function. You can name it whatever you want! The ":" tells the computer you will define the function in the next line of code.
Now, we already have the instructions to draw square. After you type the above line of code, press the spacebar on your keyboard once before each of your code in lines 5-12. It will now look something like this:
You just indented your code! That means, you made it clear to the computer what lines of code are for your "function definition" and what are just regular lines of code. This is further clarified by the straight line, as you can see to the right:
12. Now you defined a function, let's run it. Type the following after line 12:
draw_square()
draw_square()
draw_square()
draw_square()
Make sure the code is now typed outside of your definition, it should align vertically with "def"* Here is your final output when you click run after step 12:
Congrats! That's the end of the tutorial. If you get any errors, type the exact code as displayed above. Use google :) and the friendly computer science community or drop us an email: turing.stem.edu@gmail.com
Play around with the numbers, try different shapes, sizes, movements. Make a cool design, or better year try displaying your name using turtle. Send us your submissions and the best one will be given a free class!
You and your child just learnt quite a lot of basics about python, and even a business concept. Here are the 2019 GCSE Computer Science crosslinks provided by this lesson:
3.2.2 Programming concepts
3.2.7 Input/output and le handling
3.2.10 Subroutines (procedures and functions)
3.2.11 Structured programming
3.3.3 Units of information
This is a FRACTION of what is taught in one of our 1-1 private sessions or our camps. Book a consultation or session for your child here.
Answers to questions in lesson:
2. LHS. Instructions to our turtle will given in the LHS, and output will be noticed in the RHS.
3. India imports aircrafts from the USA. USA exports aircrafts to the USA.
4. Instead of easter = turtle.Screen(), you can literally give any name instead of "easter". For example, turing = turtle.Screen() Some names might not work, as they names of commands that are used in python (e.g. data, as, function, etc.)
5. Most mainstream colours are available. Try red, green, yellow, purple. Even "light blue" and "dark blue" work. "bg" stands for background.
Comments