1
00:00:00,870 --> 00:00:04,200
Very often I've asked you in the quizzes

2
00:00:04,200 --> 00:00:06,090
especially to play computer.

3
00:00:06,720 --> 00:00:11,310
And the reason is because this skill of pretending to be a computer reading

4
00:00:11,310 --> 00:00:15,630
through your code and imagining what you going to do each time is really,

5
00:00:15,630 --> 00:00:18,510
really useful, especially when you're debugging.

6
00:00:19,290 --> 00:00:23,370
So let's comment out the previous block and try the next block.

7
00:00:24,270 --> 00:00:25,620
Take a look at this code.

8
00:00:26,180 --> 00:00:28,040
It takes an input

9
00:00:28,250 --> 00:00:32,689
in the form of an integer and it ask the user for their year of birth.

10
00:00:33,380 --> 00:00:38,380
And then it uses an if statement to check if they were born between 1980 and

11
00:00:39,110 --> 00:00:43,220
1994, in which case they're classified as a millennial.

12
00:00:44,270 --> 00:00:49,220
But if there were born later than 1994, then they're classified as a Gen Z.

13
00:00:50,000 --> 00:00:52,130
So depending on which country you're from,

14
00:00:52,310 --> 00:00:55,670
there's different classifications for your particular generation.

15
00:00:56,210 --> 00:00:59,450
This is just the typical words that you hear on the internet.

16
00:00:59,780 --> 00:01:02,540
You're a millennial, you're a Gen Z, you're a baby boomer,

17
00:01:02,840 --> 00:01:07,100
and this comes from a lot of the history of the US. But nonetheless,

18
00:01:07,160 --> 00:01:12,160
I want you to run the code and I want you to see what happens when I put in

19
00:01:12,590 --> 00:01:15,950
1994. Absolutely nothing,

20
00:01:16,220 --> 00:01:21,110
so we have our bug right there. Run through the code line-by-line and evaluate

21
00:01:21,110 --> 00:01:25,610
each statement. For example, if year is equal to 1990,

22
00:01:25,910 --> 00:01:29,630
will line 77 evaluate to true or to false?

23
00:01:30,170 --> 00:01:32,630
What if year is equal to 1994?

24
00:01:33,020 --> 00:01:38,000
Look at each line of code and follow the logic and check what it will evaluate

25
00:01:38,000 --> 00:01:38,833
to.

26
00:01:38,870 --> 00:01:43,100
So I want you to play computer and figure out what is the problem,

27
00:01:43,520 --> 00:01:47,210
and then go ahead and fix the bug. Pause the video now.

28
00:01:50,480 --> 00:01:51,313
All right. So

29
00:01:51,410 --> 00:01:55,070
let's pretend that we got 1994 as the input.

30
00:01:55,490 --> 00:01:57,320
So now I'm the computer

31
00:01:57,380 --> 00:02:01,040
and I know that this year is equal to 1994.

32
00:02:01,730 --> 00:02:04,520
Now with this year being equal to 1994,

33
00:02:04,730 --> 00:02:09,139
I go into this if statement so is 1994,

34
00:02:09,440 --> 00:02:13,340
greater than 1980? Yes it is.

35
00:02:13,430 --> 00:02:15,980
So this actually becomes true.

36
00:02:17,000 --> 00:02:22,000
Now I have to check the second condition and it also has to be true for this if

37
00:02:22,040 --> 00:02:25,880
block to be triggered. So is 1994,

38
00:02:26,270 --> 00:02:28,790
less than 1994? No, it's not.

39
00:02:28,820 --> 00:02:32,210
It's actually less than equal to 1994,

40
00:02:32,570 --> 00:02:36,620
or it's equal to 1994. So in this case,

41
00:02:36,680 --> 00:02:39,050
this condition becomes false.

42
00:02:39,530 --> 00:02:44,530
And we know that if we try to combine a true and a false then it actually just

43
00:02:44,930 --> 00:02:46,070
becomes a false.

44
00:02:46,490 --> 00:02:47,930
So this gets skipped.

45
00:02:48,830 --> 00:02:51,980
Now, next, we look at the next statement, right?

46
00:02:52,430 --> 00:02:56,840
If 1994 is greater than 1994,

47
00:02:57,380 --> 00:03:00,610
well, that's also not true. It be greater or equal to,

48
00:03:00,940 --> 00:03:02,800
or it could just be equal to.

49
00:03:02,950 --> 00:03:06,280
So this condition is also false.

50
00:03:06,700 --> 00:03:10,810
So that means it's also going to skip this next line and there's no more lines

51
00:03:10,810 --> 00:03:14,680
of code left, which is why the computer doesn't print anything.

52
00:03:15,190 --> 00:03:19,420
So let's restore our code to before we started playing computer

53
00:03:19,960 --> 00:03:24,960
and we can identify that this problem occurs because there is no bucket that

54
00:03:26,500 --> 00:03:29,470
actually catches the 1994.

55
00:03:30,160 --> 00:03:35,160
We could simply fix this code by changing one of these conditions to be greater

56
00:03:35,590 --> 00:03:38,950
than or equal to either here or here.

57
00:03:39,640 --> 00:03:44,530
And that means that the year 1994 is not skipped over in our conditions.

58
00:03:44,890 --> 00:03:48,880
And when we hit run, it will actually tell us that we are in fact,

59
00:03:49,210 --> 00:03:49,900
a Gen Z.

