python_lab / basics.py
Score: 0 / 0
>>> import python_lab

Learn Python the way you'll actually use it — by running it.

Five short, hands-on modules. Every idea comes with a live console you can poke at, so you see exactly what Python does instead of just reading about it.

No installation needed — everything runs right here.
01

Operators

Arithmetic, comparison, and logical operators — the building blocks of every expression.

02

Input & Expressions

Get input from users, build math expressions, and run simple calculations.

03

Conditionals

if, elif, else, and nested conditions to make your programs decide things.

04

Loops

for loops, while loops, and nested loops to repeat work automatically.

05

Functions

Package logic into reusable functions with parameters and return values.

Module 01

Operators

Operators are the small symbols that do the work in Python: adding numbers, comparing values, and combining true/false logic. There are three families you'll use constantly.

TypeOperatorsExampleMeaning
Arithmetic+ - * / // % **7 // 2Floor division → 3
Comparison== != > < >= <=5 >= 5Returns True or False
Logicaland or notTrue and FalseCombines booleans → False

Playground: Arithmetic & Comparison

console
# Click an operator button above

Playground: Logical Operators

A =
true
B =
false
Tap a box to flip it
console

Quick check

What does 10 % 3 evaluate to?
True and False evaluates to:
Module 02

User Input, Expressions & Calculations

input() pauses a program and waits for the person using it to type something. Whatever they type comes back as text (a string), which you can then use inside math expressions.

Try it: input()

console
# Type a name and press Run

Simple calculation: BMI calculator

A classic "simple calculation" program: take a couple of numbers, plug them into a formula, print the result.

console
# bmi = weight / (height ** 2)

Quick check

input() always returns a value of which type?
Module 03

if, elif, else & Nested Conditions

Conditions let your program choose what to do. Python checks each branch top to bottom and runs the first one that's true.

Try it: age classifier

age < 13Child
age < 18Teenager
age < 60Adult
elseSenior
console
# Enter an age and press Check

Nested conditions: grading system

A nested condition is just an if inside another if — here, each grade band is a deeper check once the score passes the previous test.

A≥ 90
B≥ 80
C≥ 70
D≥ 60
F< 60
console
# Enter a score and press Grade it

Quick check

In an if / elif / else chain, how many branches can run?
Module 04

for Loop, while Loop & Nested Loops

Loops repeat work so you don't have to copy-paste code. A for loop repeats a fixed number of times; a while loop repeats until a condition becomes false.

Step through a for loop

current value of i
console

while loop: countdown

console

Nested loops: multiplication table

A loop inside a loop. The outer loop picks a row, and for every row, the inner loop fills in every column — that's why the grid fills cell by cell.

console

Quick check

How many times does for i in range(2, 8): run?
A while loop stops when:
Module 05

Functions, Parameters & Return Values

A function is a reusable machine: you feed it input (parameters), it does some work, and it hands back a result (the return value).

The function machine

arguments in
function
return value
?
console
# Fill in the arguments and call the function

Quick check

In def add(a, b):, what are a and b called?
What happens if a function has no return statement?