Skip to content
Crayon CS

Make it comfy

Lesson style

Quick mode shows the key picture, a summary and the practice. Good for a refresher.

Theme
Font

Both fonts are designed to be easy to read. Some readers with dyslexia prefer Lexend.

Text size
Spacing
Animations

Lesson 2 of 26 · about 12 min

Values, types and arithmetic

Every value in Python has a type (whole number, decimal, text, true/false), and the type decides what you can do with it.

🧭 What you need first: Your first recipe for a computer

The story

Imagine a shop assistant who is brilliant but extremely literal. You hand them two things and say “add these.”

  • Hand them 3 apples and 4 apples: they say “7 apples.”
  • Hand them two name tags, “3” and “4”: they stick them side by side: “34.”
  • Hand them 3 apples and a name tag: they freeze. “I don’t know how to add an apple to a name tag.”

Python is that assistant. Before it does anything with a value, it checks what kind of thing the value is. That kind is called its type, and it decides what “add” means.

Another way: kitchen measurements

In a recipe, “2 cups” and “2 eggs” are both “2”, but you can’t add them into “4 cupeggs.” A number only makes sense together with what kind of thing it counts. In Python, the type is that “what kind.”

Another way: phone numbers

Your phone number is made of digits, but you’d never add two phone numbers together. It’s really a label that happens to use digits. Python would store it as text (a string), not a number, for exactly that reason.

Play with it

Poke at values and types

Run this, then change things. Try type(2.0), "ha" * 3, 10 / 2, or 5 + "5" (that last one will complain, on purpose).

Name it

The four basic types

Type What it is Examples
int whole numbers (integers) 7, -3, 1000000
float numbers with a decimal point (“floating point”) 3.5, 0.1, 2.0
str text, called a string "hello", '7', "" (empty)
bool true or false, called a Boolean True, False

Arithmetic operators:

Operator Meaning Example Result
+ - * add, subtract, multiply 6 * 7 42
/ divide (always gives a float) 10 / 4 2.5
// floor division: how many whole times it fits 17 // 5 3
% remainder (say “mod”): what’s left over 17 % 5 2
** power 2 ** 3 8

Think of // and % as sharing pizza: 17 slices among 5 people. Each gets 17 // 5 = 3 slices, and 17 % 5 = 2 are left in the box.

Order of operations works like school math: ** first, then * / // %, then + -. So 2 + 3 * 4 is 14, not 20. Parentheses go first: (2 + 3) * 4 is 20. When in doubt, add parentheses. They make code clearer for humans too.

An expression is anything Python can work out to a single value: 2 + 3, "a" * 3, 7 > 5. Python evaluates it, meaning it calculates the answer.

Build it

Turn seconds into minutes

A video is 500 seconds long. Store how many whole minutes it is in a variable called minutes, and the leftover seconds in seconds. Then print them.

Challenge

Predict, then check

What does print("5" * 3) show?

What is 2 + 3 * 4 ** 2?

Remember it

What type is the result of 10 / 2?

Got it?

Finish the lesson to color it in on your map and collect its concept cards.

Did this lesson click?