Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FOUNDATIONS / CHAPTER 01 / Learn / LESSON 03
Third class. Sometimes a number arrives as text. We convert it first, then calculate.
int("25") creates a whole number, while float("1.8") creates a decimal. Converted values can take part in +, -, *, /, and **. Health Engine uses BMI as the connecting example.
BMI (Body Mass Index) is a simple formula: weight divided by height squared. In Python, exponentiation is **. So height ** 2 is height×height. The full expression: weight / height ** 2.
Important: operator order. ** runs before /. You do not need parentheses for this formula, but if you get confused, weight / (height ** 2) is the same and easier to read.
With our lesson data — height 1.8 m and weight 75.0 kg — BMI is about 23.15. That sits in a “normal” range, but classification comes next class. Today we only compute and show the number.
Mini example:
h = 1.8
w = 75.0
value = w / h ** 2
print(round(value, 2))round(..., 2) rounds to two digits after the decimal point — handy for reading in the console.
Common mistake: writing height ** 2 as height * 2 (doubling, not squaring). Or using text values without int/float — then division breaks.
** raises to a power. With height float("1.8") and weight float("75.0"), BMI is about 23.15. Values stay visible in the code — no hidden input().
ENGINE STANDBY
›