01 / GETTING STARTED · LESSON 02

Variables and numbers

Name values and calculate a small capacity budget.

11 min · learn at your pace

Give a value a useful name

device_count = 4 binds the name device_count to an integer. Later expressions can use that name. Assignment uses one equals sign. Python chooses a value’s type from the value itself: 4 is an int, 4.5 is a float, and "4" is a str.

Names are case-sensitive. Prefer descriptive snake_case names, and avoid names such as list or str that already identify built-in tools. Changing a variable does not change calculations you made earlier; run the calculation again when its inputs change.

Calculate before you format

Use +, -, *, and / for arithmetic. Division with / produces a floating-point result; // performs floor division. Parentheses make the intended order clear. Keep numbers as numbers while calculating so you can sort, compare, and add them later.

You can inspect type(total_gb) in the terminal. The checks for this exercise inspect your variables, so printing an answer without saving it under the requested name will not finish the task.

Try an example.py
device_count = 4
memory_per_device = 16
total_gb = device_count * memory_per_device
print(total_gb, type(total_gb))
YOUR TURN

Put it into practice.

For 7 devices with 8 GB each and a 6 GB reserve, create device_count, memory_per_device, reserved_gb, total_gb, and usable_gb. Keep the totals as integers and print usable_gb.

See an explained solution
One way to solve it.py
device_count = 7
memory_per_device = 8
reserved_gb = 6
total_gb = device_count * memory_per_device
usable_gb = total_gb - reserved_gb
print(usable_gb)

The inputs stay separate from the calculation. This makes it easy to change a device count later and see how the usable capacity changes.