1
00:00:00,480 --> 00:00:01,680
In this exercise,

2
00:00:01,680 --> 00:00:04,590
you are going to be writing a function

3
00:00:04,590 --> 00:00:07,800
that calculates how many cans of paint you need

4
00:00:07,800 --> 00:00:09,990
in order to paint a wall,

5
00:00:09,990 --> 00:00:14,010
given the height and width of the wall.

6
00:00:14,010 --> 00:00:16,440
So what you're going to do is you're going write a function,

7
00:00:16,440 --> 00:00:20,220
and it has to be called paint_calc

8
00:00:20,220 --> 00:00:24,030
because the code on lines 10 to 13

9
00:00:24,030 --> 00:00:26,460
makes sure that we get the inputs,

10
00:00:26,460 --> 00:00:29,130
we work out the coverage of our paint,

11
00:00:29,130 --> 00:00:32,369
and we use your function, paint_calc,

12
00:00:32,369 --> 00:00:36,150
in order to output the printed statement

13
00:00:36,150 --> 00:00:39,840
to tell the user how many cans of paint they need.

14
00:00:39,840 --> 00:00:44,010
The way to work out the area of a wall

15
00:00:44,010 --> 00:00:47,790
is to multiply the height by the width,

16
00:00:47,790 --> 00:00:52,790
and then we divide that number by the coverage of the paint

17
00:00:53,610 --> 00:00:56,940
in order to work out how many number of cans we need.

18
00:00:56,940 --> 00:01:01,230
Now, because the shops don't sell you a fractional can,

19
00:01:01,230 --> 00:01:03,720
and believe me, I've tried to ask for that,

20
00:01:03,720 --> 00:01:06,150
you have to always round upwards,

21
00:01:06,150 --> 00:01:08,010
y ou can't round down.

22
00:01:08,010 --> 00:01:11,010
So even if it was 1.1 cans,

23
00:01:11,010 --> 00:01:13,440
you will need to purchase two cans,

24
00:01:13,440 --> 00:01:18,060
or so says the sales agent at my local home hardware store.

25
00:01:18,060 --> 00:01:20,580
Now, take a look at the instructions,

26
00:01:20,580 --> 00:01:24,390
you'll see that the Example Input and Example Outputs

27
00:01:24,390 --> 00:01:26,640
and the format that they need to be.

28
00:01:26,640 --> 00:01:29,040
In this case, we're saying that the first number

29
00:01:29,040 --> 00:01:33,360
in the Input is the height and the second is the width,

30
00:01:33,360 --> 00:01:35,130
but in reality it doesn't really matter

31
00:01:35,130 --> 00:01:38,160
because area is worked out in either way,

32
00:01:38,160 --> 00:01:39,870
height times width or width times height,

33
00:01:39,870 --> 00:01:41,580
and it doesn't really matter.

34
00:01:41,580 --> 00:01:43,020
But what it does matter

35
00:01:43,020 --> 00:01:46,080
is to figure out how to round up a number,

36
00:01:46,080 --> 00:01:47,460
and I've put a hint

37
00:01:47,460 --> 00:01:49,770
into the instructions from Stack Overflow.

38
00:01:49,770 --> 00:01:52,770
You could also search for your own ways

39
00:01:52,770 --> 00:01:54,720
of figuring this out.

40
00:01:54,720 --> 00:01:57,390
But, have a go at writing the code,

41
00:01:57,390 --> 00:02:00,450
and hit Submit when you think you're ready,

42
00:02:00,450 --> 00:02:03,033
and check it against the pre-made tests.

43
00:02:06,270 --> 00:02:10,229
The first thing we need to do is to define our function.

44
00:02:10,229 --> 00:02:13,980
So in Python, that is the "def keyword", space,

45
00:02:13,980 --> 00:02:15,480
and then the name of the function.

46
00:02:15,480 --> 00:02:19,020
And we said that it has to match the line

47
00:02:19,020 --> 00:02:22,140
that we already created to call the function on line 12.

48
00:02:22,140 --> 00:02:24,200
So it has to be called paint_calc.

49
00:02:25,350 --> 00:02:27,240
And then we have a set of parentheses ()

50
00:02:27,240 --> 00:02:30,990
where we can put the inputs to our function.

51
00:02:30,990 --> 00:02:35,430
In this case, it's height, width, and the coverage.

52
00:02:35,430 --> 00:02:38,610
Now, we haven't put any inputs into our function just yet

53
00:02:38,610 --> 00:02:42,450
because remember, our function is a multi-use tool.

54
00:02:42,450 --> 00:02:45,000
It's something that we can use again and again

55
00:02:45,000 --> 00:02:47,190
by putting in different inputs.

56
00:02:47,190 --> 00:02:51,180
So for example, the function len() can take any list,

57
00:02:51,180 --> 00:02:54,600
and it will work out the length of the list

58
00:02:54,600 --> 00:02:57,120
or how many items are in the list.

59
00:02:57,120 --> 00:02:59,220
So the inputs can always change,

60
00:02:59,220 --> 00:03:00,840
but we define in our function

61
00:03:00,840 --> 00:03:03,870
how we want to work with those inputs.

62
00:03:03,870 --> 00:03:07,950
After our definition for our function name and inputs,

63
00:03:07,950 --> 00:03:10,950
we create the actual body of the function.

64
00:03:10,950 --> 00:03:14,580
And we do that by indenting into the function.

65
00:03:14,580 --> 00:03:16,620
The first thing we do is we calculate

66
00:03:16,620 --> 00:03:17,940
the number of cans we need

67
00:03:17,940 --> 00:03:21,180
by multiplying the height by the width to work out the area,

68
00:03:21,180 --> 00:03:23,580
putting a parenthesis around this,

69
00:03:23,580 --> 00:03:28,290
and then we divide it by the coverage of the paint.

70
00:03:28,290 --> 00:03:32,670
This is going to be a decimal number in many cases,

71
00:03:32,670 --> 00:03:35,280
so we have another line on line 5

72
00:03:35,280 --> 00:03:37,980
where we round up the cans.

73
00:03:37,980 --> 00:03:42,980
In order to round it up, we use the math module

74
00:03:43,980 --> 00:03:48,390
and we use the math.ceil() method.

75
00:03:48,390 --> 00:03:51,450
This is going to go to the ceiling of the number,

76
00:03:51,450 --> 00:03:53,340
which basically means rounding it up

77
00:03:53,340 --> 00:03:55,320
to the nearest whole number.

78
00:03:55,320 --> 00:03:57,270
And we pass our number of cans

79
00:03:57,270 --> 00:03:59,610
as the input into this function,

80
00:03:59,610 --> 00:04:04,560
and then we calculate it and store it inside round_up_cans.

81
00:04:04,560 --> 00:04:06,810
And then finally, we print out the message,

82
00:04:06,810 --> 00:04:09,960
You'll need round_up_cans cans of paint,

83
00:04:09,960 --> 00:04:14,310
inserting our number of cans of paint rounded up

84
00:04:14,310 --> 00:04:16,380
into that print statement.

85
00:04:16,380 --> 00:04:19,050
And the way that our function is going to work

86
00:04:19,050 --> 00:04:23,520
is we've already defined our function on lines 3 to 6,

87
00:04:23,520 --> 00:04:25,500
and then on line 12,

88
00:04:25,500 --> 00:04:29,220
we actually call the function, passing in actual values.

89
00:04:29,220 --> 00:04:32,820
So in this case, the first input as the height,

90
00:04:32,820 --> 00:04:34,980
the second input as the width,

91
00:04:34,980 --> 00:04:38,733
and the coverage as whatever is defined on line 11.

92
00:04:39,660 --> 00:04:41,910
And when that line of code is run,

93
00:04:41,910 --> 00:04:46,143
then we get our output printed into the output area.

