1
00:00:00,660 --> 00:00:05,370
Now that we've pretty much completed all of the logic and functionality of this

2
00:00:05,370 --> 00:00:08,850
calculator, it's time to add in the bells and the whistles,

3
00:00:09,120 --> 00:00:13,200
including adding in the calculator logo and also checking for any bugs.

4
00:00:14,280 --> 00:00:16,590
Adding the calculator logo is pretty simple.

5
00:00:17,280 --> 00:00:19,200
You've done this loads of times before.

6
00:00:19,860 --> 00:00:22,740
All we have to do is import it from the art module,

7
00:00:23,070 --> 00:00:27,480
and then we're going to print it at the beginning of our calculator function.

8
00:00:28,470 --> 00:00:29,310
So this way

9
00:00:29,370 --> 00:00:33,630
when we get to the end and the user wants to start a fresh calculation,

10
00:00:33,930 --> 00:00:38,910
we'll also show them a logo again. Now the next thing to notice,

11
00:00:39,060 --> 00:00:42,630
this is a bit of a bug that you might've seen or not.

12
00:00:43,290 --> 00:00:48,090
But what happens if we try to enter a number with a decimal point?

13
00:00:48,630 --> 00:00:52,470
Let's say we want to calculate 4.5 multiplied by 2.

14
00:00:54,180 --> 00:00:55,860
Our program has already crashed

15
00:00:55,950 --> 00:01:00,000
as soon as I've entered 4.5 and hit enter. As a challenge,

16
00:01:00,030 --> 00:01:03,930
can you diagnose what went wrong and fix this bug? I'll give you a few seconds

17
00:01:03,930 --> 00:01:05,530
to pause the video before I give you the 

18
00:01:06,050 --> 00:01:06,883
solution.

19
00:01:08,750 --> 00:01:10,070
Alright. Here's the solution.

20
00:01:10,220 --> 00:01:15,110
The bug goes back to our lesson on datatypes.Notice how it's giving us an error

21
00:01:15,230 --> 00:01:17,030
and it's pointing to this line

22
00:01:17,060 --> 00:01:22,040
number 26. Line number 26 takes this input

23
00:01:22,100 --> 00:01:26,570
which is a string and converts it into an integer. But of course,

24
00:01:26,780 --> 00:01:30,380
a number with the decimal place shouldn't be converted into an integer.

25
00:01:30,770 --> 00:01:35,480
We should actually hold it as a floating point number instead. This way

26
00:01:35,480 --> 00:01:38,330
we're able to perform more accurate calculations.

27
00:01:38,600 --> 00:01:40,670
So instead of just 4 times 5,

28
00:01:40,670 --> 00:01:44,360
we can do 4.5 times 5.5, for example.

29
00:01:44,930 --> 00:01:48,410
So instead of using int here, I'm going to change that to float

30
00:01:48,920 --> 00:01:53,510
and I'm going to do the same here for num2. Now, when we hit run,

31
00:01:53,690 --> 00:01:58,160
I can actually perform calculations using numbers with decimal places,

32
00:01:58,520 --> 00:02:01,340
but I can also use numbers which are whole.

33
00:02:01,670 --> 00:02:06,020
So let's multiply 2.5 by 2, the answer is 5,

34
00:02:06,080 --> 00:02:10,789
and you can see that all the numbers are being reported to a greater level of

35
00:02:10,789 --> 00:02:14,030
accuracy, meaning we have numbers after the decimal point.

36
00:02:14,420 --> 00:02:18,260
And this is all because we converted that int to a float.

37
00:02:19,850 --> 00:02:23,240
Now that there's a lot more features that you could add to your calculator.

38
00:02:23,540 --> 00:02:28,310
You could add a square root capability, you could add exponent capability,

39
00:02:28,670 --> 00:02:32,990
but the important thing here was really for you to see how functions that

40
00:02:32,990 --> 00:02:35,810
provide outputs are really useful

41
00:02:35,840 --> 00:02:40,840
when you come to a more complex program where you can take the output from one

42
00:02:42,650 --> 00:02:47,360
function call and pass it into the next function

43
00:02:47,360 --> 00:02:49,100
call as an input.

44
00:02:49,940 --> 00:02:53,660
So this output can be reused in different parts of the code.

45
00:02:54,170 --> 00:02:59,170
And this not only allows us to reduce repetition and also make our more reusable

46
00:03:00,400 --> 00:03:01,420
and more modular,

47
00:03:01,720 --> 00:03:06,720
but also it gives us the flexibility of performing more actions after a function

48
00:03:08,590 --> 00:03:10,990
has completed. Now,

49
00:03:10,990 --> 00:03:15,370
we're going to be using a lot of the concepts that we've learned here today in

50
00:03:15,520 --> 00:03:19,780
tomorrow's capstone project. A lot of things I've explained,

51
00:03:19,780 --> 00:03:22,240
including things like the recursion

52
00:03:22,240 --> 00:03:26,980
where we're calling a function within its own definition or things like setting a

53
00:03:26,980 --> 00:03:29,860
flag using a wall loop to continue

54
00:03:29,860 --> 00:03:33,070
some piece of code execution is all going to come in really,

55
00:03:33,070 --> 00:03:34,360
really handy tomorrow.

56
00:03:34,780 --> 00:03:38,050
So make sure that if there's anything that you don't understand here

57
00:03:38,380 --> 00:03:43,380
that you review it and you're comfortable with what the code is doing before you

58
00:03:43,480 --> 00:03:47,410
proceed. That's all for today and I'll see you tomorrow.

