🚀 Alguni Start learning

Unit 9: Toolboxes

Borrowing code others wrote.

Unit 9 of 31 in Python for kids. Its 5 lessons are Borrowing Tools, The Maths Toolbox, Dates, Counting Days and Toolbox Master — below is everything each one explains, and a question or two from it to try.

Every sample on this page was run through real Python before it shipped, and prints exactly what it says it prints.

This unit opens with a fortnight’s trial of everything — no card needed — or with a family plan, bought in the iPhone app. The first two units of every track are free for ever. Try it in the app.

🧰 Borrowing Tools

You do not have to write everything

A module is a box of code somebody already wrote. import opens the box, and then you reach inside it with a dot.

Python

import math

print(math.sqrt(9))

It prints

3.0

Taking just one tool out

from ... import ... lifts one thing out of the box, so you can use its name on its own — no dot needed.

Python

from math import sqrt

print(sqrt(25))

It prints

5.0

Giving the box a shorter name

as renames it for the rest of your program. Handy when the real name is long.

Python

import random as r

r.seed(1)
print(r.randint(1, 6))

It prints

2

Try it yourself

What does the dot in math.sqrt mean?

  • Multiply
  • Look inside the math box for the thing called sqrt
  • End of the line
  • A decimal point

Where should your imports go?

  • At the very top of the file
  • At the bottom
  • Inside every function
  • Anywhere, it makes no difference to a reader

Answer them in the app

📐 The Maths Toolbox

Rounding your own way

floor always goes down, ceil always goes up. round goes to whichever is nearer.

Python

import math

print(math.floor(4.8))
print(math.ceil(4.1))
print(round(4.5))

It prints

4
5
4

Python rounds .5 to the even one

That is not a bug. Always rounding .5 upwards would slowly push every average too high, so Python picks the even neighbour instead. round(4.5) is 4 and round(5.5) is 6.

Python

print(round(4.5))
print(round(5.5))
print(round(2.675, 2))

It prints

4
6
2.67

Pi and powers

math.pi is a number, not a function, so it needs no brackets. ** does powers just fine on its own.

Python

import math

print(round(math.pi, 4))
print(2 ** 10)

It prints

3.1416
1024

Try it yourself

What does this print?

Python

import math

print(math.floor(7.9))
print(math.ceil(7.1))

Why does math.sqrt(16) print 4.0 rather than 4?

  • It is a mistake
  • sqrt always answers with a decimal number
  • 16 is a decimal
  • Because of the import

Answer them in the app

📅 Dates

A date is a thing you can hold

The datetime module has a date you can build from a year, month and day — and then ask it questions.

Python

from datetime import date

party = date(2026, 12, 25)
print(party)
print(party.year)
print(party.month)

It prints

2026-12-25
2026
12

What day of the week was it?

strftime turns a date into text however you like. %A is the weekday name, %d the day, %B the month name, %Y the year.

Python

from datetime import date

d = date(2026, 8, 7)
print(d.strftime("%A"))
print(d.strftime("%d %B %Y"))

It prints

Friday
07 August 2026

Try it yourself

What does this print?

Python

from datetime import date

d = date(2026, 8, 7)
print(d.day)

In strftime, what does %A give you?

  • The year
  • The name of the weekday
  • The month number
  • A capital A

Answer them in the app

⏳ Counting Days

How many sleeps?

Take one date away from another and you get a timedelta — a length of time. Ask it for .days.

Python

from datetime import date

today = date(2026, 8, 7)
party = date(2026, 12, 25)
print((party - today).days)

It prints

140

Jumping forwards

Add a timedelta to a date to move through the calendar. It handles months and leap years for you.

Python

from datetime import date, timedelta

d = date(2026, 2, 26)
print(d + timedelta(days=3))

It prints

2026-03-01

Try it yourself

What does this print?

Python

from datetime import date, timedelta

d = date(2026, 8, 7)
print(d + timedelta(days=7))

Why do you write .days at the end?

  • To make it print nicely
  • Subtracting gives a length of time, and .days asks that length how many days it is
  • It is optional
  • To turn it into a date

Answer them in the app

🏆 Toolbox Master

Try it yourself

What does this print?

Python

import math

print(math.ceil(2.1) + math.floor(2.9))

Answer it in the app