INTERACTIVE ONLINE COURSE

Python 3

FOR BEGINNERS


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)


ALL REVIEWS
LESSON 6
PAGE 2 / 4
Learning with Turtle!
Home >>> Online Lessons, Python 3

An Equilateral Triangle

Run the program below. You will probably wonder why we turn by 1200...
Editor - lesson_6.py
       
Graphical Mode in Python done
Console/Output done
DETAILS

Well... it's simple. The initial angle is 00, and to get the supplement of the 600 angle, we apply the geometric formula 1800 - 600 = 1200:

So, after moving forward 100 pixels, we turn by 1200 and draw the second side. We turn again by 1200 and return to the starting point by moving forward 100 pixels again. Geometry is cool!

EXERCISES

Try to draw a trapezoid with the characteristics shown below:

Then, can you draw the shapes below?


Choose your own dimensions and colors!

Note, the web graphic screen is 300 pixels high, and you start from the center, so only 150 are visible upwards...

Pen Up, Pen Down!

The turtle can lift its pen so that it doesn't draw while it moves. Use the functions penup() (pen up) and pendown() (default, pen down) for this! This way, you can move around the screen...

Test the following program in the editor to understand the mechanism:

import turtle
t = turtle.Turtle()
t.forward(30)
t.penup()
t.forward(30)
t.pendown()
t.forward(30)
t.penup()
t.forward(30)
t.pendown()
t.forward(30)


Command Shortcuts

We can use fd() instead of forward(), bk() instead of backward(), as well as lt() or rt(), pu() or pd()...
Try to solve the proposed exercise,
then proceed to the next page.
 home   list  CONTENTS   perm_identity   arrow_upward