1
00:00:00,090 --> 00:00:04,140
All right. So in this lesson, we're going to be debugging our leap year

2
00:00:04,170 --> 00:00:09,060
coding exercise. You've done this coding exercise before, you wrote this code

3
00:00:09,120 --> 00:00:12,660
which checks to see if a year is a leap year.

4
00:00:12,990 --> 00:00:16,290
It prints leap year if it's true, and not leap year

5
00:00:16,350 --> 00:00:18,000
if it's not a leap year.

6
00:00:18,600 --> 00:00:21,540
All you have to do is to fix this code.

7
00:00:22,020 --> 00:00:27,020
So use what you learned about debugging and try to fix this coding exercise.

8
00:00:27,720 --> 00:00:28,800
So pause the video now.

9
00:00:29,120 --> 00:00:29,953
Okay.

10
00:00:32,630 --> 00:00:33,830
All right. So first off,

11
00:00:33,860 --> 00:00:37,370
let's go ahead and just run our code and see if it works.

12
00:00:37,760 --> 00:00:40,490
And then we're going to enter a known leap year.

13
00:00:41,120 --> 00:00:45,080
So a quick Google away lets see when is a leap year.

14
00:00:45,560 --> 00:00:49,220
Well, 2020 seems to be a leap year. So let's try that.

15
00:00:49,250 --> 00:00:53,660
Let's check 2020. And we get an error.

16
00:00:53,780 --> 00:00:58,160
So errors are good. They're much easier to fix than the Programming problems

17
00:00:58,160 --> 00:00:59,210
which have no errors.

18
00:00:59,720 --> 00:01:04,720
And it tells us that there's a problem on line three and it's a type error,

19
00:01:05,390 --> 00:01:09,860
not all arguments converted during string formatting.

20
00:01:10,250 --> 00:01:14,090
What does that mean? Well, what's a type error anyways?

21
00:01:14,320 --> 00:01:19,320
A type error is when you're trying to do something with the wrong data type. In

22
00:01:20,810 --> 00:01:25,190
our case, it's pointing at line three. So if we take a look at line three,

23
00:01:25,190 --> 00:01:26,150
what's happening here?

24
00:01:26,870 --> 00:01:31,870
Well, currently we're trying to take the year that the user inputted, so 2020, and

25
00:01:33,260 --> 00:01:38,260
divide it by four to see if the remainder is equal to zero.

26
00:01:39,080 --> 00:01:42,380
Now, this is a little bit harder to solve than the previous one.

27
00:01:42,890 --> 00:01:47,660
But what you should realize is that it's pointing towards a type error,

28
00:01:48,020 --> 00:01:51,170
so what data types have we got going on? Well,

29
00:01:51,230 --> 00:01:56,000
if we go ahead and print the type of our year,

30
00:01:56,750 --> 00:01:59,780
then you can see that it's of class string.

31
00:02:00,410 --> 00:02:05,000
But if we print the type of this 4 that

32
00:02:05,000 --> 00:02:08,510
we're trying to divide it by, that is of class int.

33
00:02:08,780 --> 00:02:12,980
So this is the problem. These two types are not matched.

34
00:02:13,280 --> 00:02:16,730
So when you try to divide a string by an integer,

35
00:02:17,120 --> 00:02:19,760
this is what ends up giving you this problem.

36
00:02:20,330 --> 00:02:24,140
So why is this a string when we entered a number?

37
00:02:24,650 --> 00:02:29,650
Well it's because the input function, remember, gives the user a prompt and then

38
00:02:30,620 --> 00:02:35,620
takes whatever they type in the console and turns it into a string.

39
00:02:36,890 --> 00:02:40,580
So in order to turn this into an int which is what we want,

40
00:02:41,030 --> 00:02:45,320
we have to wrap it around a set of parentheses and then type

41
00:02:45,380 --> 00:02:49,850
convert it into an integer. And now when we run it again,

42
00:02:50,120 --> 00:02:54,860
we can see that it actually works. And we're happy that we fixed our code.

43
00:02:55,580 --> 00:02:57,110
Once you're done with this challenge,

44
00:02:57,260 --> 00:03:00,860
head over to the next one and complete the final debugging exercise.

