What Is Python and How to Install It? Write Your First Python Program (Python for Kids)

What Is Python and How to Install It? Write Your First Python Program (Python for Kids)

Bu yazıyı Türkçe okuyun · Leer en español

You type a few lines of code, and a turtle draws a rainbow spiral on a black background. In this post, the first step of the Python for Kids series, I explain what Python is, where it is used and how to install it on your computer. By the end, you will have drawn that spiral on your own computer.

  • Age group: 10 and up, no coding experience needed
  • Time: About 30 minutes
  • What you need: a Windows or Mac computer and an internet connection

Video

If you prefer watching to reading, the video version of this post is below. All episodes of the series are in the “Python for Kids” playlist.

The narration is in Turkish. English subtitles are available: click CC on the video.

What is Python?

Python is a programming language: a language we use to tell the computer what to do. It was created in 1991 by the Dutch programmer Guido van Rossum. It is not named after the snake but after Monty Python, a British comedy group. Today it is one of the most popular programming languages in the world, and it is completely free.

Why start with Python?

Python code reads almost like an English sentence. To print “Hello!” on the screen, the C++ language needs seven lines:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello!" << endl;
  return 0;
}

Arduino code looks a lot like this language too. In Python, the same job takes one line:

print("Hello!")

Fewer symbols, fewer mistakes, more fun.

Where is Python used?

  • Artificial intelligence: most chatbots and image recognition apps are written in Python.
  • Games: you can make your own games; in the last episode of the series we write a game together.
  • Websites: Python runs behind big websites such as Instagram.
  • Science and space: scientists use Python to study data from space and turn it into charts.
  • Robots: boards such as Raspberry Pi and micro:bit are programmed with Python.
  • Automation: boring, repetitive jobs on the computer can be handed over to Python.

Downloading Python

  1. In your browser, go to python.org/downloads.
  2. On Windows, choose Windows from the Downloads menu and download the Windows installer (64-bit) under the latest Python 3 release.
  3. On a Mac, download the macOS 64-bit universal installer of the latest release from the macOS page.

Python is completely free, and you do not need to create an account.

Installing on Windows and Mac

On Windows:

  1. Double-click the file you downloaded to open it.
  2. At the bottom of the installer window, be sure to tick the Add python.exe to PATH box. This box lets the computer find Python from anywhere.
  3. Click Install Now and wait for the installation to finish.

On a Mac: open the .pkg package you downloaded and click the Continue buttons. IDLE goes into the Python folder inside your Applications folder.

First commands in IDLE

A program called IDLE is installed together with Python. On Windows, type IDLE in the Start menu and open it. The window that opens is called the Shell. A command you type next to the >>> sign runs as soon as you press Enter. Try these one by one:

>>> print("Hello!")
Hello!
>>> 7 * 8
56
>>> print("Ha" * 3)
HaHaHa
  • The print command writes the text inside the brackets on the screen.
  • Python is also a great calculator: type 7 * 8 and it answers 56.
  • If you multiply a piece of text in quotes by 3, the text repeats three times.

Our first program: a rainbow spiral

Instead of typing commands one at a time, we can also write a program file. In IDLE, open a new window with File → New File and type the code below. Save the file as spiral.py and press F5.

# Python Turtle Rainbow Spiral - ozandamci.com
import turtle

screen = turtle.Screen()
screen.bgcolor("black")

pen = turtle.Turtle()
pen.speed(0)  # fastest drawing
pen.pensize(2)

colors = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"]

for i in range(150):
    pen.color(colors[i % 7])  # use the 7 colors in turn
    pen.forward(i * 1.5)      # a slightly longer line each time
    pen.left(59)

pen.hideturtle()
turtle.done()

In the window that opens, the turtle uses the seven colors in turn, draws a slightly longer line each time and turns 59 degrees; the result is a colorful spiral. I explain how this code works line by line in the first episode of the series.

If something goes wrong

  • If IDLE does not appear in the Start menu: run the installer again and remember to tick “Add python.exe to PATH”.
  • Do not name your file turtle.py: Python would open your file instead of its own turtle library, and the program would not work.
  • If you see a red error message: check the quotes, the brackets and the spaces at the start of the lines.

What’s next?

Now you have Python on your computer and you have run your first program. In the first episode of the series, we will make the turtle draw a square and a star and learn how loops work. All episodes are listed in the Python for Kids section on the English page. Feel free to ask your questions in the comments.

“What Is Python and How to Install It? Write Your First Python Program (Python for Kids)” için 2 yorum

Bir Cevap Yazın