Skip to content
IT Vizag
← Python Basics

▶ 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

Lesson 5 of 10 · 1 min read

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

🔒 Code example: sign up free (above) to unlock it.

% (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:

🔒 Code example: sign up free (above) to unlock it.

Real example: splitting a bill

Four friends eat at a restaurant in MVP Colony:

🔒 Code example: sign up free (above) to unlock it.

round(value, 2) keeps two decimal places, which is right for rupees and paise.

Watch out for float surprises

🔒 Code example: sign up free (above) to unlock it.

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.

Tip: 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.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend