Bootcamp Curriculum • 5 Modules • 12 Chapters • Multi-Language Runner (Python, JS, Java, C++) • Interactive Memory Trace • AI Mentor
CHAPTER 02 · FOUNDATIONS6 min read

Data types & math operations

Numbers and text behave completely differently in computer memory. '123' + '456' is '123456', while 123 + 456 is 579. Understanding types prevents subtle bugs and unlocks math calculations.

By the end of this chapter, you can:
  • Distinguish strings, integers, floats, and booleans.
  • Convert types using int(), float(), and str().
  • Calculate bill splits with percentage tips (Tip Calculator logic).
Explanation DepthTailor the level of detail to your learning goal
💻 Standard College Notes

Primitive types, type conversion, and math operators.

Python supports int, float, bool, and str. Type casting is done via int(), float(), str(), and bool(). Division with / always returns a float in Python 3; use // for floor division.

💡Order of operations follows PEMDAS: Parentheses, Exponents (**), Multiplication/Division, Addition/Subtraction.

Primitive types & type conversion

Python features 4 primary primitive types: str (text), int (whole numbers), float (decimals), and bool (True/False). Convert between them explicitly.

example_1.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.

The Tip Calculator project logic

The iconic Day 2 project: calculate the total bill with a percentage tip and split the cost evenly among people.

example_2.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.
✦ Interactive Dry-Run Visualizer

Memory Trace: Tip Calculator Math & Division

Watch how float arithmetic accumulates the total bill and splits it.

STEP1 / 5
1bill = 150.0👉 Executing
2tip = 150.0 * 0.12
3total = bill + tip
4per_person = total / 5
5print(per_person)
VariableValue in MemoryData Type
bill150.0float
Initialize float bill in memory

Stores 150.0 with decimal precision.

Console Stream (stdout)
(No output generated yet)
Line 1: bill = 150.0

🔧 Float Arithmetic & Conversion Bug

A billing script was supposed to calculate a 15% tip on a $100 bill, but concatenated string characters instead of computing math.

⚡ +100 XP
fix_bug.pyPython 3.10
⚡ Quick Revision Quiz

Predict The Output (2 Questions)

Question 1 of 2:
What is the type of the expression: 10 / 2?
Question 2 of 2:
What does 8 // 3 evaluate to in Python?

Your lightbulb moment

✧

The key takeaway
Primitive types govern memory representation. Use type converters when reading data, and use float operations for currency math.

Make it yours

Try changing the tip percentage to 18% and split among 4 people to test how the per-person total recalculates.

Try editing the code in the playground above in Python, JavaScript, Java, or C++, and use the step-by-step Dry-Run Table to inspect how variables mutate in memory. If you get stuck, click the 🤖 AI Doubt Solver button on your screen for instant explanations!