Numbers, remainder, bools

Seat counts are ints. GST maths can produce a fractional rupee you must not treat as a till total. True and False are the answers to comparisons. Remainder (%) is how a lab numbers benches in a cycle.

Museum ticket window

Price × quantity is a real bill.

You will be able to

  • Use int arithmetic for counts and paise-like totals
  • Use remainder (%) for cycles
  • Treat True/False as comparison results

Ints, floats and remainder

Seat counts and roll numbers are integers. Division can produce a fractional result — fine for a mean temperature, dangerous as a running GST total (later: paise or Decimal). Remainder % answers ‘which bench in a cycle of 4’. Mixed int and float follows the float on a laptop; here keep one kind in a function.

True and False are the values of comparisons (hours > 8). You can store a flag and print it. Chained comparisons like 1 < x < 10 exist on a laptop; here write nested ifs. Hex, binary, complex numbers and bitwise ops exist for device registers and science — know they exist; campus fees do not need 0xFF.

Bools are not decoration

if ok: on a laptop treats 0, empty list and empty string as false. A clerk-facing API should still return explicit "ok" / "Reject" or 0 / 25 so a CSV does not store False as a blank. Use bools inside the program; be explicit at the edge.

Laptop extras (not in this sandbox)

print(17 // 3, 17 % 3, 2 ** 8)
print(0xFF, 3+5j)
print(1 < 4 < 10)

Words that matter

int
Whole number — counts, paise, rolls.
float
Fractional number — science readings, not a till.
remainder %
What’s left after dividing — cycles and wrapping.

Common mistakes

Avoid: Using float for a 40,000-row rupee total.

Do this: Integer paise or Decimal; format at the edge.

Run it step by step

Each box is a real program. Press Run, change a number, Run again — the output must follow your code.

1. Step 1 — named amounts

HRA as 40 percent of basic.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

2. Step 2 — remainder as a cycle

Bench 0,1,2,3 then wrap. 5 % 4 is 1.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Example program — Half CTC and a flag

Print the name, not a fresh literal, so a raise updates both.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Your turn — Remainder 10 % 3

Print the remainder of 10 divided by 3 so 1 appears.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Self-assessment

Check your understanding before you mark the lesson complete.

1. 10 % 3 is…
2. True/False usually come from…

Progress is stored in a browser cookie on this device.