All tutorials & guides

Python

Python for Kids: Write Your First Program in 15 Minutes

6 min read · beginner

Aarav gets ₹150 pocket money every week. He wants a new cricket ball that costs ₹450. How many weeks must he save? You could work it out in your head, but today you will make a computer do it, and you will write the instructions yourself in Python.

By the end of this tutorial you will have a working program that talks, does maths, makes a decision and repeats a task. That is a real program, not a toy.

Why Python?

Python is a programming language: a way of writing instructions that a computer can follow. It is popular with beginners because it reads almost like English. It is also used by professionals for websites, science and artificial intelligence, so what you learn today keeps being useful.

A program is simply a list of instructions. The computer runs them from top to bottom, one line at a time, and does exactly what you wrote. Not what you meant, what you wrote. That is why small details like spelling and brackets matter.

Four building blocks

Your first program uses four ideas that appear in almost every program ever written.

1. Printing. print() shows something on the screen. Text goes inside quotes.

2. Variables. A variable is a labelled box that stores a value. pocket_money = 150 makes a box called pocket_money and puts 150 inside it. You can use the name later instead of the number.

3. Decisions with if. if lets the program choose. If a condition is true, it does one thing; else it does another. Notice the colon : at the end of the line and the spaces at the start of the next line. Those spaces (called indentation) tell Python which lines belong inside the if.

4. Loops with for. A loop repeats work. for week in range(1, 4): runs the indented lines three times, with week becoming 1, then 2, then 3. (range stops just before the second number.)

Try it: the pocket-money planner

You can use Python installed on a computer (free from the official Python website) or any online Python editor in your browser.

  1. Open a new file or editor window.
  2. Type the program below carefully. Typing it yourself, rather than copy-pasting, helps your brain learn the patterns.
  3. Run it. In most editors there is a Run button or you can press F5.
  4. Compare your output with the one shown below.
# My first Python program: a pocket-money planner
name = "Aarav"
pocket_money = 150      # rupees per week
cricket_ball = 450      # price of the ball he wants

print("Hello,", name + "!")
weeks = cricket_ball / pocket_money
print("Weeks needed to save for the ball:", weeks)

if weeks <= 4:
    print("That's less than a month. You can do it!")
else:
    print("That's a long wait. Maybe save a bit extra?")

savings = 0
for week in range(1, 4):
    savings = savings + pocket_money
    print("Week", week, "savings: Rs", savings)

When you run it, you should see:

Hello, Aarav!
Weeks needed to save for the ball: 3.0
That's less than a month. You can do it!
Week 1 savings: Rs 150
Week 2 savings: Rs 300
Week 3 savings: Rs 450

Lines that start with # are comments. Python ignores them; they are notes for humans.

Why does it say 3.0 and not 3? The / sign does division and always gives a number with a decimal point, called a float. Whole numbers like 150 are called integers.

Make it your own

Now experiment. Change one thing at a time and run again:

  1. Put your own name in name.
  2. Change cricket_ball to the price of something you want, like a book or a badminton racquet. What happens when the number of weeks goes above 4?
  3. Change range(1, 4) to range(1, 9) to see eight weeks of savings.
  4. Break it on purpose: delete a closing quote and run it. Read the error message. Python tells you the line number where it got confused. Learning to read errors is a real programmer skill.

For parents

You do not need to know Python to help. Sit beside your child, ask them to explain what each line does, and encourage them to predict the output before pressing Run. Mistakes and error messages are a normal part of programming, not a sign of failure. Fifteen calm minutes of experimenting is worth more than an hour of copying code.

What you learned

  • A program is a list of instructions the computer follows from top to bottom.
  • print() shows output, and variables store values with a name.
  • if and else let a program make decisions, and indentation shows which lines belong where.
  • A for loop with range() repeats work a set number of times.
  • / gives a decimal answer (a float), and error messages tell you where to look.

Where to go from here

You have written a program with the same building blocks used in real software. In a full Python course, students go further: working with text, lists and dictionaries, writing their own functions, handling errors, and eventually using Python for data and machine learning. Want to build more? Book a free demo class and code live with a teacher who can answer questions as they come up.

Want your child to build more like this?

Book a free 1:1 demo class with a Curiovio teacher. Your child builds a real project live, and you see how we teach.

Book a free demo class

Free: build your child's first AI project in 7 days

One short, fun task a day for you and your child. Only a web browser needed.