#5 Python Playground: Turtle Graphics | Computer Programming & Coding for Kids & Beginners

preview_player
Показать описание
Lesson 5

Let's draw with Turtle Graphics!

Liam
Let's draw with Turtle Graphics!

Emma
Hey, Liam.
I'm getting a little bored with just displaying the letters.

Liam
Then, let's try drawing!
Let the turtle walk and draw a line.

Emma
Sounds like fun!
I'd love to try it.

Liam
Let's draw a straight line with turtle graphics!

This program displays a "straight line" by moving the turtle straight ahead.

First, let's open a new file from IDLE and enter this program!

from turtle import *
shape("turtle")
forward(100)
done()

Emma
What do these codes mean?

Liam
This is an instruction to use Turtle Graphics.
This is an instruction to make the turtle appear.
This is an instruction to go straight forward 100.
This is an instruction.

Emma
I understand.

Liam
Once you've written your program in a file, give the file a name and save it.
Next, let's run this program.
When you run it, another window will open, the turtle will walk, and a straight line will be drawn.

Emma
Oh, the turtle is drawing a line!
Can this turtle walk backwards?

Liam
You can make the turtle walk backwards with "back"
And you can also use “left” and “right” to turn the turtle sideways.

Emma
I found that I could draw a favorite picture by making the turtle walk in various directions.

Liam
Let's draw a square with Turtle Graphics!

Next, let's create a program to draw a square.
Create a program to draw a square by repeating the "go straight and turn 90 degrees" action four times.
Now, let's open a new file from IDLE and enter this program!

from turtle import*
shape("turtle")
for i in range (4):
forward(100)
left(90)
done()

Emma
What do these codes mean?

Liam
This is an instruction to repeat the following process four times
This is a straight forward instruction to advance 100.
This is an instruction to turn 90 degrees to the left.

Emma
I understand.

Liam
Once you've written your program in a file, give the file a name and save it.
Next, let's run this program.

Emma
Wow, the turtle drew a square!

Emma
By the way, are the four spaces at the beginning of the line necessary?

Liam
It's called indentation, and it's a necessity.

Emma
What is indentation?

Liam
Indentation is entered with the tab key or space key.
However, IDLE has an automatic indentation feature.
If you don't need the indentation, you must remove it yourself.
Since indentation makes sense in Python, putting indents where you don't need them will result in an error.

Emma
What is indentation used for?

Liam
Python indentation is a way of telling a Python interpreter that the group of statements belongs to a particular block of code.
A block is a combination of all these statements.
Block can be regarded as the grouping of statements for a specific purpose.
Python uses indentation to highlight the blocks of code.
All statements with the same distance to the right belong to the same block of code.
If a block has to be more deeply nested, it is simply indented further to the right.

Emma
I now understand the indentation.

Liam
Let's draw a colorful star with Turtle Graphics!

Next, we will create a program to draw a colorful star.
You can draw a star by repeating the action "go straight and turn 144 degrees" five times.
This time we are going to color in the lines.
So let's open a new file from IDLE and enter this program!

from turtle import*
shape("turtle")
col = ["red" ,"blue" ,"yellow" ,"green" ,"purple" ]
for i in range (5):
color(col[I])
forward(200)
left(144)
done()

Emma
What do these codes mean?

Liam
This is an instruction of the colors to use.
This is an instruction to repeat the following process five times.
This is an instruction to change the color of the line.
This is an instruction to advance 200 straight ahead.
This is an instruction to turn 144 degrees to the left.

Once you've written your program in a file, give the file a name and save it.
Next, let's run this program.

Emma
Cool! The turtle drew a colorful star!

In this lesson, I learned to draw with Turtle Graphics.

Liam
Well done.
Рекомендации по теме
Комментарии
Автор

good stuff, thanks for your tutorials for kids, I ll recommend it

py_tok
Автор

How are you running the file? I'm using Note++ and cannot for the life of me ran this file.

Native
Автор

The turtle is not running in my laptop

craft-o-fun
Автор

idk why but when i do want to draw a square i type all of the commands but still doesnt draw anything

xxxsplinterxxx