انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

The turtle draws

Section 7: Drawing with the turtleLesson 7.1 · ⏱ 8 min

The turtle library has a turtle that draws as it walks. forward moves forward, and left and right turn by degrees.

🐍 A square
import turtle
t = turtle.Turtle()
t.color("blue")
t.pensize(4)
for i in range(4):
    t.forward(150)
    t.left(90)
The turtle drawing in Robo Python🐍 Open the code in Robo Python ↗
💡 Tip
The angle = 360 ÷ the number of sides. 120 for a triangle, and 60 for a hexagon.

📌 Another example: a triangle

Three sides, and we turn 120 degrees each time.

🐍 A triangle
import turtle
t = turtle.Turtle()
t.color("green")
t.pensize(4)
for i in range(3):
    t.forward(150)
    t.left(120)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

A red square with sides of 120.

👀 Show the solution
🐍 Solution
import turtle
t = turtle.Turtle()
t.color("red")
for i in range(4):
    t.forward(120)
    t.left(90)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python

Result: a red square.

Medium

A hexagon: 6 sides, and a 60 turn.

👀 Show the solution
🐍 Solution
import turtle
t = turtle.Turtle()
t.color("blue")
for i in range(6):
    t.forward(90)
    t.left(60)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python

Result: a hexagon.

Hard

A circle with circle, and a square around it.

👀 Show the solution
🐍 Solution
import turtle
t = turtle.Turtle()
t.color("purple")
t.circle(60)
t.penup()
t.goto(-60, 0)
t.pendown()
for i in range(4):
    t.forward(120)
    t.left(90)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python

Result: a circle inside a square.

Finished the lesson? Mark it so your progress counts.