1
00:00:00,750 --> 00:00:05,750
Now the next step is to think about reproducing the bug that you've encountered,

2
00:00:06,840 --> 00:00:10,950
because when you encounter it once but you don't encounter it the next time

3
00:00:11,310 --> 00:00:15,930
that becomes a really difficult bug to fix. Go ahead

4
00:00:15,930 --> 00:00:18,570
and uncomment the next block of code.

5
00:00:19,590 --> 00:00:23,130
And we're going to comment out the previous section because we're done with it

6
00:00:23,130 --> 00:00:27,240
now. So this is the only part that should be active in your main.py.

7
00:00:28,260 --> 00:00:31,020
In this section, we're going to try and reproduce the bug.

8
00:00:31,170 --> 00:00:32,340
So when we run the code,

9
00:00:32,369 --> 00:00:36,840
sometimes it will work and it will print out one of the dice images from this

10
00:00:36,840 --> 00:00:40,260
list, but occasionally you will get an error.

11
00:00:41,310 --> 00:00:45,840
These types of bugs are really difficult because you might test your code only

12
00:00:45,840 --> 00:00:49,080
once or twice, and it looks all fine. It works.

13
00:00:49,380 --> 00:00:51,750
But then occasionally you get an error.

14
00:00:52,350 --> 00:00:55,470
And the important thing is to reproduce that error.

15
00:00:55,500 --> 00:00:58,170
When does that error actually happen?

16
00:00:59,040 --> 00:01:02,850
And based on that knowledge, we can fix our code.

17
00:01:03,570 --> 00:01:08,570
Try to reproduce the bug yourself and try to notice when it happens and see if

18
00:01:10,320 --> 00:01:14,400
you can change the code so that it always produces this error.

19
00:01:14,690 --> 00:01:19,690
[inaudible],

20
00:01:20,390 --> 00:01:25,160
We've got a list of dice images, which are just emojis.

21
00:01:25,610 --> 00:01:30,610
And we've also got this random number, dice number between 1 and 6.

22
00:01:31,730 --> 00:01:34,310
Now, when we try to pick out of our list,

23
00:01:34,850 --> 00:01:37,400
occasionally we get an error.

24
00:01:38,180 --> 00:01:42,530
Now we have to notice when the error occurs, and to reproduce the bug

25
00:01:42,560 --> 00:01:46,490
we have to figure out which of these numbers is actually causing the problem.

26
00:01:46,910 --> 00:01:51,470
So we know that this is a random number between 1 and 6

27
00:01:51,920 --> 00:01:55,220
and if we check the documentation, it tells us that randint

28
00:01:55,220 --> 00:01:57,680
works a little bit differently from range.

29
00:01:58,070 --> 00:02:02,570
It will return a random integer in the range of a and b,

30
00:02:02,930 --> 00:02:06,050
including both end points. So in our case,

31
00:02:06,080 --> 00:02:11,080
both 1 and 6 could be generated and it could be any number.

32
00:02:11,210 --> 00:02:15,950
So if that was equal to 1, well, does it generate an error?

33
00:02:16,010 --> 00:02:18,890
No, it just picks out this particular item.

34
00:02:19,370 --> 00:02:22,250
But what if it was 2 or 3 or 4?

35
00:02:22,520 --> 00:02:25,790
Or what if we tested 6? Well,

36
00:02:25,790 --> 00:02:30,230
now every time we hit run, you can see we get an error.

37
00:02:30,980 --> 00:02:34,490
And now that we've got our error to show up consistently,

38
00:02:34,610 --> 00:02:39,610
it's a lot easier to debug because we know that the index error list index out of

39
00:02:40,160 --> 00:02:43,400
range happens when this dice number is 6.

40
00:02:43,850 --> 00:02:48,080
So when we go back to our previous code, well,

41
00:02:48,110 --> 00:02:53,110
we can't use 6 in this list because lists start counting from 0.

42
00:02:54,440 --> 00:02:59,150
So to get this dice 1, we need dice_num to be 0.

43
00:02:59,590 --> 00:03:02,410
And then this is 1, 2, 3, 4, 5,

44
00:03:02,770 --> 00:03:07,420
and 6 is somewhere out here and it doesn't exist. Now,

45
00:03:07,450 --> 00:03:12,190
go ahead and fix this code so that all the dice images are represented and we

46
00:03:12,190 --> 00:03:16,240
never see this error again. Alright.

47
00:03:16,240 --> 00:03:19,420
So that is as simple as shifting down these numbers.

48
00:03:19,870 --> 00:03:22,870
So instead of making a random number between 1 and 6,

49
00:03:23,110 --> 00:03:28,000
we actually want a random number between 0 and 5. And now,

50
00:03:28,030 --> 00:03:30,190
no matter how many times we run our code,

51
00:03:30,460 --> 00:03:32,530
we're never going to get that error show up again.

