Python Programming for Kids • Online Free Coding Editor / Interpreter • Turtle Graphics

Python for Kids
Online Programming Free Editor
Receiving data from the Earth server.

Using Turtle Graphics programming in Python, you can change the pen and filling color:
pendown() , pd() pd()
Sets the pen down and the spaceship resumes leaving a trail as it moves on the canvas.
penup() , pu() pu()
Sets the pen up and the spaceship stops leaving a trail as it moves on the canvas.
pensize(value), width(value) pensize(25)
Sets the pen size to a number of value pixels.
pencolor(color) pensize("#ff00ff")
Sets the stroke color (default: black). The color parameter can be set using standard color codes or html HEX values.
Standard colors: "black" (
), "blue" (
), "lime" (
), "cyan" (
), "red" (
), "magenta" (
"yellow" (
), "white" (
), "brown" (
), "tan" (
), "green" (
), "aquamarine" (
), "salmon" (
"purple" (
), "orange" (
), "gray" (
fillcolor(color) fillcolor("yellow")
Sets the fill color (default: black). The color parameter can be set using standard color codes or html HEX values.
color(c_stroke[,c_fill]) color("red","green")
Changes the stroke and fill colors at the same time. If c_fill is missing, the color set by c_stroke is used for both attributes.
Turtle Graphics in Python is suuuper cool and you can create amazing simple shapes using some interesting functions for your programs:
stamp() stamp()
Draws a copy of the spaceship graphic on the canvas at the current position, like a stamp.
begin_fill() begin_fill()
A new path is set and it describes a geometric shape (a polygon).
end_fill() end_fill()
Closes the current path and fills the shape using the fill color (see fillcolor()).

Example. The program below draws a green square. The fill color is chosen, then the path is started by begin_fill() command:
from turtle import *
for i in range(4):

The desired geometric shape is drawn, s end_fill() closes the path and fills it with green. The desired geometric shape is drawn, so end_fill() closes the path and fills it with green.
fill() print(fill()) ; if (fill()) ...
The function returns a boolean value based on the state of the fill mode: True or False, being useful in certain slightly more complex programs.
dot() dot()
A point is drawn at the current position. The function is very useful if we want to use it in combination with penup(), drawing only certain important points along the way of the spaceship.

Example. Below we draw only the corners of a square:
from turtle import *
for i in range(4):
circle(radius, angle, step) circle(50,360,100)
A circle is characterized by radius, i.e. the distance from the center to any of its points. Next, you need to understand that a circle is made of step points. You can draw a full circle using 360 degrees for the value of angle or only a part of it, more precisely an arc of a circle imposing a correspondingly smaller angle. The larger the step, the finer the drawing of the geometric shape will be.
The magic of geometry. When step = 4 , a square will be drawn (like a rhombus), and when step = 5 , a pentagon. If we set step = 6 , we will get a hexagon, etc. The more we increase the value of the parameter step, the more the polygon approaches the shape of the circle that inscribes it!

Example. Test the code below to understand it better:
from turtle import *
#triangle, square, ...
for i in range(6):
#finally, the circle

variable_name = clone() clone1 = clone()
A new variable, addressable by variable_name , will retain a new graphical object (an identical spaceship) which can be commanded using the Python programming language. The position on the screen and the rest of the parameters will also be identical with all the attributes of the "mother" ship. You can create one clone, two ... or as many as you want!
Caution! The "mother" ship can still be controlled through direct commands such as fd(80), but clone1 in the example will receive statements like clone1.fd(50) because they are different objects on the screen, and the addressing must be done properly!
Important note! Python is an interpreter and executes the instructions sequentially, i.e. one after the other. Thus, the graphic objects on the screen will alternately perform the animations depending on the program you created!
Example. Test the code below:

from turtle import *
clone1 = clone()
clone2 = clone()
clone2.write("One spaceship, two clones",False,"left",("Verdana","24px","bold"))
clone2.pu(); clone2.bk(50)
fd(90); circle(70) #back to "mother" ship
variable_name = Turtle() spaceship2 = Turtle()
A new variable, addressable by variable_name , will hold a new graphic object (a new spaceship). Unlike clone(), this function creates a new object with default parameters and positioned at the (0,0) coordinates.
Example. Test the code below:

from turtle import *
#main spaceship
#a new spaceship
ss2 = Turtle()

A little trick. To simulate the simultaneous motion of two spaceships, we can move them alternatively by small steps (like 1 pixel), as in the example below:

from turtle import *
#main spaceship
color("yellow"); speed(0)
#a new spaceship
ss2 = Turtle()
for i in range(120):
    lt(3); fd(1)
    ss2.rt(3); ss2.fd(1)

The speed of the two objects in this situation decreases considerably...
print(stuff) print("Aloha, Mars!")
Prints useful information in the Log/Output data panel.
Simple text: print("This is a text!")
Contents of variable x : print(x)
Contents of variables x, y, z : print(x,y,z)
Expressions: print(x**x)
Separator (optional). Specify how to separate the objects, if there is more than one. Default is ' ' (a blankspace). Example: print(1,2,3,4,5,sep='_')
Ending line (optional). Specify what to print at the end. Default is '\n' (line feed) Examples: print(1,2,3,4,5,end='---') , print(1,2,3,4,5,end='\n\n') , print(1,2,3,4,5,end='\n------\n') , etc.
write(message,move,align,style) write("Hello!")
The text of message is written graphically starting from the current position. move parameter is a boolean (True / False) and allows the ship to move or not while the message is being plotted on the canvas. align can get values like "left" , "center" or "right". The text style is entered as a tuple: (font, size, font_style).

from turtle import *
write("Fun on Mars!", False, "left", ("Verdana","32px","bold"))

• The font_style parameter can be "normal" , "italic" or "bold" .
• To move the ship without drawing the line, we can of course use penup() before the write() command:

from turtle import *
write("Fun on Mars!", True, "left", ("Verdana","32px","bold"))

• Only message is required as a parameter, the rest being optional. Play with different values ​​for the text style!
For example, the names of some standard fonts are: "Tahoma", "Verdana", "Arial", "Calibri", etc.
input(optional_message) input() , input("x = ")
The input() function allows user input from the keyboard. optional_message is a String, representing a default message before the input.
Example: username = input("Your name is: ") ; print("Hello,", username)

Important note.This function returns a string. In order to get the right type for various purposes, use type casting as bellow:

#as a string
x = input()
#converted as an integer
y = int(input("y = "))
#converted as a floating number
z = float(input("z = "))
print(x,y,z) #simple printing
print(x*2,y*2-1,z*2+1) #using extra operators

Run the code and enter 12 each time, for example. Python is cool!

Mind the type casting technique though.. you can't convert 'nine' to 9, or ... 3.14 to 3. You need to know what you are asking and what might be entered by the user!
Turtle Graphics is an educational programming concept, designed in 1967 by Daniel G. Bobrow, Wally Feurzeig, Seymour Papert and Cynthia Solomon. Today the Logo language is remembered mainly for its use of "turtle graphics", in which commands for movement and drawing produced line graphics either on screen or with a small robot called a "turtle". See more info at [].

Seymour Papert from MIT's Artificial Intelligence Laboratory invented TurtleGraphics in the 70s. Find out his description of it:
... "the turtle." You can think of this as a drawing instrument... Imagine that you are looking at a computer screen. On it you see a small turtle, which moves when you type commands in a language called "turtle talk," leaving a line as it goes. The command "Forward 50" causes the turtle to move straight ahead a certain distance. "Forward 100" will make it move in the same direction twice as far. You soon get the idea that the numbers represent the distance it moves; they can be thought of as turtle steps. Now if you want to make it go in a different direction, you give it a command like "Right 90." It stays in the same place but turns on itself, facing east if it had previously been facing north. With this knowledge you should easily be able to make it draw a box. If that's easy for you, you can think about how to draw a circle, and if that's easy you can try a spiral. Somewhere you will meet your level of difficulty, and when you do I'll give you this piece of advice: Put yourself in the place of the turtle. Imagine yourself moving in the outline of a box or a circle or a spiral or whatever it may be.
Turtle Graphics in Python 3 can be considered an attractive mode of introducing programming concepts to kids. By simply writing small instructions, students can create interesting programs, executed animatedly - the effect is immediately visualized on the screen! As you can guess, recursive subroutines can also be run, as well as many other complex programs.
The turtle module is an extended reimplementation of the same-named module from the Python standard distribution up to version Python 2.5. The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. After the "from turtle import *" line, give it the command forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command right(25), and it rotates in-place 25 degrees clockwise. By combining together these and similar commands, intricate shapes and pictures can easily be drawn.

Here on Mars your turtle is a spaceship!

NOTE. We can use only some of the Python 3 functions and commands in the browser, and they are described in detail on these info tabs. The online programming environment is a simulation built in another web programming language called JavaScript, and the animation speed is clearly superior to native Python programs!
Here you can see other Turtle Graphics programs created in Python 3. Click to load the corresponding code in the editor:
Create a Free Account Now!
Our Friends World Map
Need Some Help?
James Webb Space Telescope
Real Weather on Mars