1
00:00:01,020 --> 00:00:02,130
In this exercise,

2
00:00:02,130 --> 00:00:03,510
we're going to write some code

3
00:00:03,510 --> 00:00:08,280
to upgrade the previous version of our BMI calculator.

4
00:00:08,280 --> 00:00:12,570
So this is our BMI calculator 2.0, if you will.

5
00:00:12,570 --> 00:00:14,250
Now, we're going to write a program

6
00:00:14,250 --> 00:00:17,280
that interprets the Body Mass Index

7
00:00:17,280 --> 00:00:20,280
instead of just simply printing out what it is,

8
00:00:20,280 --> 00:00:21,450
because for most people,

9
00:00:21,450 --> 00:00:23,730
these numbers don't really mean anything.

10
00:00:23,730 --> 00:00:25,530
If you take a look in the description pane,

11
00:00:25,530 --> 00:00:27,870
you'll see that there is a chart

12
00:00:27,870 --> 00:00:32,870
that shows how different BMI are classified by doctors.

13
00:00:33,330 --> 00:00:35,340
If you are within the green band,

14
00:00:35,340 --> 00:00:39,270
so if your BMI is between 18.5 and 25,

15
00:00:39,270 --> 00:00:42,930
then that is considered the normal weight.

16
00:00:42,930 --> 00:00:45,180
And depending on which band you are in,

17
00:00:45,180 --> 00:00:47,460
then there are different classifications

18
00:00:47,460 --> 00:00:49,650
that doctors have come up with.

19
00:00:49,650 --> 00:00:50,820
What we're going to do

20
00:00:50,820 --> 00:00:53,910
is we're going to take a user's height and weight,

21
00:00:53,910 --> 00:00:55,740
we're going to calculate the BMI,

22
00:00:55,740 --> 00:00:58,080
and we're going to output a print statement

23
00:00:58,080 --> 00:01:03,080
telling them, "Your BMI is X...", whatever it is we calculated,

24
00:01:03,210 --> 00:01:07,140
and then we're going to give them an interpretation.

25
00:01:07,140 --> 00:01:10,740
You are underweight or you have a normal weight,

26
00:01:10,740 --> 00:01:13,290
and you can check in the description pane

27
00:01:13,290 --> 00:01:16,980
for exactly what your output needs to match.

28
00:01:16,980 --> 00:01:18,930
Now, I know people are a little bit sensitive

29
00:01:18,930 --> 00:01:22,620
about these topics, and there are certain statements,

30
00:01:22,620 --> 00:01:26,100
like you are obese or you are slightly overweight,

31
00:01:26,100 --> 00:01:28,020
that can be difficult,

32
00:01:28,020 --> 00:01:31,800
but just know that these are words that have come

33
00:01:31,800 --> 00:01:36,420
from the clinical interpretations of the BMI

34
00:01:36,420 --> 00:01:41,010
and we are just going to output them from our calculator.

35
00:01:41,010 --> 00:01:43,290
Take a look at some of the Example Inputs

36
00:01:43,290 --> 00:01:46,050
and Example Outputs and see what it is

37
00:01:46,050 --> 00:01:49,230
that you are expected to create.

38
00:01:49,230 --> 00:01:51,810
And then see if you can remember

39
00:01:51,810 --> 00:01:55,890
how to create the BMI calculator second time round

40
00:01:55,890 --> 00:01:59,010
and add in a slight interpretation

41
00:01:59,010 --> 00:02:01,620
like the ones you see in the description pane.

42
00:02:01,620 --> 00:02:03,993
Have a go at this coding exercise.

43
00:02:12,650 --> 00:02:14,940
So the first step is to do what we did before,

44
00:02:14,940 --> 00:02:18,150
which is to calculate the BMI using the formula

45
00:02:18,150 --> 00:02:21,600
of weight divided by height squared.

46
00:02:21,600 --> 00:02:24,540
And once we've gotten hold of that value,

47
00:02:24,540 --> 00:02:27,540
then we can use our if and else statements

48
00:02:27,540 --> 00:02:30,513
to figure out which interpretation we should give them.

49
00:02:31,410 --> 00:02:36,410
In the case where their BMI is less than 18.5,

50
00:02:36,510 --> 00:02:41,510
then we should print out, "Your BMI is..." whatever it is,

51
00:02:42,030 --> 00:02:44,940
and then "you are underweight."

52
00:02:44,940 --> 00:02:47,400
And this condition is checked

53
00:02:47,400 --> 00:02:50,043
in the first if statement on line 5.

54
00:02:51,120 --> 00:02:53,670
Now, because there are many conditions,

55
00:02:53,670 --> 00:02:55,770
not just a single one,

56
00:02:55,770 --> 00:02:59,220
we're going to need to use the "elif statement".

57
00:02:59,220 --> 00:03:03,330
So we write elif, which stands for else if,

58
00:03:03,330 --> 00:03:06,300
and we can provide another condition to check.

59
00:03:06,300 --> 00:03:10,290
Well, if the BMI is not less than 18.5,

60
00:03:10,290 --> 00:03:12,150
we go on to line 7.

61
00:03:12,150 --> 00:03:15,420
elif is the BMI less than 25.

62
00:03:15,420 --> 00:03:19,290
So that means if the first statement on line 5 was false,

63
00:03:19,290 --> 00:03:21,870
then line 7 actually checks to see

64
00:03:21,870 --> 00:03:26,220
if the BMI is between 18.5 and 25.

65
00:03:26,220 --> 00:03:29,010
And when the BMI is within that range,

66
00:03:29,010 --> 00:03:32,970
then the print statement, "Your BMI is X,

67
00:03:32,970 --> 00:03:36,033
you have a normal weight."  will be printed out.

68
00:03:37,170 --> 00:03:40,350
Next, we have two further elif statements

69
00:03:40,350 --> 00:03:43,920
to check if their BMI is between 25 and 30

70
00:03:43,920 --> 00:03:46,830
and also between 30 and 35,

71
00:03:46,830 --> 00:03:50,403
and we print out the corresponding interpretation.

72
00:03:51,750 --> 00:03:55,980
Finally, we cap off our conditional statement with an else

73
00:03:55,980 --> 00:03:59,040
which covers all the other situations.

74
00:03:59,040 --> 00:04:01,710
And in this case, because we've been pretty granular

75
00:04:01,710 --> 00:04:03,540
with our different conditions,

76
00:04:03,540 --> 00:04:04,740
the only other condition

77
00:04:04,740 --> 00:04:07,020
that's going to trigger the else statement

78
00:04:07,020 --> 00:04:10,950
is if the BMI is 35 or over.

79
00:04:10,950 --> 00:04:14,220
And in this case, we give them the final interpretation

80
00:04:14,220 --> 00:04:16,470
inside this print statement.

81
00:04:16,470 --> 00:04:19,380
If you had any issues with getting the code

82
00:04:19,380 --> 00:04:22,530
to pass the tests in the previous slide,

83
00:04:22,530 --> 00:04:25,710
then see if you can understand

84
00:04:25,710 --> 00:04:28,170
what's going on in this code solution

85
00:04:28,170 --> 00:04:30,813
and try to fix your code as needed.

