Programming from zero

Types and operators theory + first problem: comparing disk usage between two servers

easyTypes and operators Must-do

Problem statement

Every value in a program has a type, what kind of thing it is. A whole number like 8080 is an int. A number with a decimal point like 245.5 is a float (Python, C++) or double (Java). Text like "web-01" is a string. The type decides what you're allowed to do with a value, and how much precision it can hold.

Operators are the symbols that work on values: +, -, *, / for arithmetic, and >, <, == for comparing two values. A comparison operator doesn't calculate a new number, it answers a yes/no question and gives you back true or false.

  • Python: diskA > diskB
  • Java: diskA > diskB
  • C++: diskA > diskB

Same symbol, same meaning, in all three, this is one of the few things that doesn't change across languages.

flowchart LR A["diskA = 245.5"] --> C{"diskA > diskB ?"} B["diskB = 198.75"] --> C C -->|"yes"| D["true"] C -->|"no"| E["false"] classDef value fill:#DBEAFE,stroke:#2563EB,color:#1E3A8A classDef compare fill:#FEF3C7,stroke:#D97706,color:#92400E classDef yes fill:#D1FAE5,stroke:#059669,color:#065F46 classDef no fill:#FEE2E2,stroke:#DC2626,color:#991B1B class A value class B value class C compare class D yes class E no

A comparison operator always produces exactly one of these two values, never a number, never the original values themselves. That's what makes it different from an arithmetic operator like + or -, which produces a new value of the same type you started with.

Common mistake: using = when you mean ==.

TEXT
Wrong: diskA = diskB (this does NOT compare)
Right: diskA == diskB (this compares)

A single = is assignment: it copies diskB's value into diskA, overwriting whatever was there. A double == is comparison: it asks "are these equal?" and changes nothing. Mixing them up is one of the most common beginner bugs in all three languages.

Your task: two servers report their disk usage in GB as diskA = 245.5 and diskB = 198.75. Print whether diskA is using more space than diskB.

Expected output:

TEXT
true

Python prints True with a capital T. Java and C++ print true. Same answer, different spelling.

Approach

The comparison itself is identical across languages, diskA > diskB. What differs is how each language declares a decimal-valued variable and prints a boolean result:

  • Python doesn't need a type keyword. diskA = 245.5 is automatically a float, and print(diskA > diskB) prints True or False.
  • Java needs the type stated up front, double diskA = 245.5;, and System.out.println(diskA > diskB); prints true or false.
  • C++ is the same idea as Java, double diskA = 245.5;, and std::cout << (diskA > diskB) << std::endl; prints 1 for true and 0 for false unless you turn on std::boolalpha, which switches it to print true / false instead.
diskA = 245.5
diskB = 198.75
print(diskA > diskB)