Kids Coding
Modules
import a library. math, random, and datetime do work you should not rewrite.
Do not rebuild the toolbox
A module is a file of tools you import. math, random, and datetime ship with Python.
math and datetime
import math
import datetime
print(math.sqrt(16))
print(math.pi)
print(datetime.date.today())Put related functions in their own file, then import it. Your main program stays short and easy to read.
Import one name
from math import
from math import sqrt
print(sqrt(25))Real life
Using a real calculator and a wall clock instead of inventing them.
math and datetime are tools already in the house. Import them. Do not rebuild them.
Clock and square root
import math
import datetime
print("Sqrt of 81:", math.sqrt(81))
print("Today:", datetime.date.today())Change one word. Run it. That is how this idea shows up outside the lesson.
Try it
Exercise 1: Import random and print a number from 1 to 3.
Show solution
import random
print(random.randint(1, 3))