▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
Numbers and maths
Integers, decimals and the maths operators, with a bill-splitting example.
🎬 Video version coming soon — read it now
Python handles two main kinds of numbers:
- int (integer): whole numbers like
5,-12,2026 - float: numbers with a decimal point, like
3.5,99.99
The maths operators
% (remainder) is more useful than it looks. n % 2 == 0 tells you whether a number is even.
Order of operations
Python follows the BODMAS rules you learned in school. Use brackets to be clear:
Real example: splitting a bill
Four friends eat at a restaurant in MVP Colony:
round(value, 2) keeps two decimal places, which is right for rupees and paise.
Watch out for float surprises
This isn't a bug in Python. Computers store decimals in binary, and some can't be stored exactly. For money, round your results, or use the decimal module in serious billing apps.
type(42) shows int and type(4.2) shows float. When something behaves oddly, check the type first.In one line
Python has ints and floats, the usual maths operators plus // and %, and round() to tidy decimals.
Share with a friend