In this exercise,
we're going to write some code
to upgrade the previous version of our BMI calculator.
So this is our BMI calculator 2.0, if you will.
Now, we're going to write a program
that interprets the Body Mass Index
instead of just simply printing out what it is,
because for most people,
these numbers don't really mean anything.
If you take a look in the description pane,
you'll see that there is a chart
that shows how different BMI are classified by doctors.
If you are within the green band,
so if your BMI is between 18.5 and 25,
then that is considered the normal weight.
And depending on which band you are in,
then there are different classifications
that doctors have come up with.
What we're going to do
is we're going to take a user's height and weight,
we're going to calculate the BMI,
and we're going to output a print statement
telling them, "Your BMI is X...", whatever it is we calculated,
and then we're going to give them an interpretation.
You are underweight or you have a normal weight,
and you can check in the description pane
for exactly what your output needs to match.
Now, I know people are a little bit sensitive
about these topics, and there are certain statements,
like you are obese or you are slightly overweight,
that can be difficult,
but just know that these are words that have come
from the clinical interpretations of the BMI
and we are just going to output them from our calculator.
Take a look at some of the Example Inputs
and Example Outputs and see what it is
that you are expected to create.
And then see if you can remember
how to create the BMI calculator second time round
and add in a slight interpretation
like the ones you see in the description pane.
Have a go at this coding exercise.
So the first step is to do what we did before,
which is to calculate the BMI using the formula
of weight divided by height squared.
And once we've gotten hold of that value,
then we can use our if and else statements
to figure out which interpretation we should give them.
In the case where their BMI is less than 18.5,
then we should print out, "Your BMI is..." whatever it is,
and then "you are underweight."
And this condition is checked
in the first if statement on line 5.
Now, because there are many conditions,
not just a single one,
we're going to need to use the "elif statement".
So we write elif, which stands for else if,
and we can provide another condition to check.
Well, if the BMI is not less than 18.5,
we go on to line 7.
elif is the BMI less than 25.
So that means if the first statement on line 5 was false,
then line 7 actually checks to see
if the BMI is between 18.5 and 25.
And when the BMI is within that range,
then the print statement, "Your BMI is X,
you have a normal weight." will be printed out.
Next, we have two further elif statements
to check if their BMI is between 25 and 30
and also between 30 and 35,
and we print out the corresponding interpretation.
Finally, we cap off our conditional statement with an else
which covers all the other situations.
And in this case, because we've been pretty granular
with our different conditions,
the only other condition
that's going to trigger the else statement
is if the BMI is 35 or over.
And in this case, we give them the final interpretation
inside this print statement.
If you had any issues with getting the code
to pass the tests in the previous slide,
then see if you can understand
what's going on in this code solution
and try to fix your code as needed.