loop
Creating multi-parameter functions

Module 4 · Creating multi-parameter functions · Lesson 1 of 5

Evaluating the BMI

Now that you can take inputs and return results, let's build something genuinely useful. The Body Mass Index needs two pieces of information — a person's weight and height — so it's a natural two-parameter function. The formula is just weight / height².

bmi(70, 1.75)
weight = 70 kgheight = 1.75 m
weight / (height * height)
22.9Normal

In Python, “height squared” is height ** 2. Feed in two numbers, get one back — and because the function returns its result, you can round it, compare it, or pass it straight into another function.

Run it yourselfruns in your browser · Python
main.py

That last point is the real lesson. A second function, category, can take the BMI value and turn it into a label — decomposition again, each function doing one job. Together they read almost like a sentence.

Run it yourselfruns in your browser · Python
main.py

One function computes, another classifies, and the second simply uses the first's returned value. Next we'll take three parameters and ask a more interesting question.