1
00:00:00,000 --> 00:00:01,990
Sometimes when you run into errors in our code.

2
00:00:02,000 --> 00:00:03,990
It's not a syntax error.

3
00:00:04,000 --> 00:00:05,990
It's not a runtime error.

4
00:00:06,000 --> 00:00:10,990
It's just that the code doesn't quite do what it was that we had intended for it do.

5
00:00:11,000 --> 00:00:14,990
These things are often also caused by typos.

6
00:00:15,000 --> 00:00:20,990
So let's make a working copy of, incrange-errors.py and we will call that

7
00:00:21,000 --> 00:00:25,990
incrange-errors-working.py.

8
00:00:26,000 --> 00:00:33,990
This is our inclusive range method from another example in this course.

9
00:00:34,000 --> 00:00:40,990
There is the code, and you will see that it calls it down here, and we will just

10
00:00:41,000 --> 00:00:41,990
run it and see what happens.

11
00:00:42,000 --> 00:00:43,990
Well, nothing happens.

12
00:00:44,000 --> 00:00:45,990
That's not a good sign.

13
00:00:46,000 --> 00:00:46,990
So why would nothing happen?

14
00:00:47,000 --> 00:00:48,990
Well, what's supposed to happen?

15
00:00:49,000 --> 00:00:53,990
The object gets initialized and it gets constructed with these parameters,

16
00:00:54,000 --> 00:01:01,990
a start, a stop and a step of 4, 25 and 3, and then it gets printed out by

17
00:01:02,000 --> 00:01:08,990
using the object as an iterator, and we can see right here, here is the iterator function.

18
00:01:09,000 --> 00:01:13,990
It's go a yield here, which makes it a generator, so that looks like it should work.

19
00:01:14,000 --> 00:01:19,990
We have the start, stop and step, and so here is the start and the stop and the

20
00:01:20,000 --> 00:01:23,990
step, and let's just run through the code here and see what happens.

21
00:01:24,000 --> 00:01:28,990
I am starting here because this is where the print is, and this is also just the

22
00:01:29,000 --> 00:01:32,990
shortest and easiest to look at piece of code. I happen to know, because I wrote this,

23
00:01:33,000 --> 00:01:37,990
that this is a little bit more of a hornets nest, and so I am just going

24
00:01:38,000 --> 00:01:41,990
to start here because it looks like a simple place to start.

25
00:01:42,000 --> 00:01:43,990
This is where the action is actually happening here.

26
00:01:44,000 --> 00:01:51,990
So i equals start, while i is greater than or equal to and that doesn't look right,

27
00:01:52,000 --> 00:01:57,990
because the start is at 4, and the stop is at 25, so I would want to run

28
00:01:58,000 --> 00:02:02,990
this loop while i <= stop.

29
00:02:03,000 --> 00:02:08,990
So that looks like a typo, and so I will change that, and I will save it and run it,

30
00:02:09,000 --> 00:02:11,990
and now we are getting some output here.

31
00:02:12,000 --> 00:02:14,990
So let's look at the output and see if it is correct.

32
00:02:15,000 --> 00:02:16,990
So we have this range.

33
00:02:17,000 --> 00:02:20,990
It starts at 4 and over here we are starting at 3. That's not right.

34
00:02:21,000 --> 00:02:28,990
And it stops at 25. Okay, well, that's plausible, and the step is 3, so 3+3

35
00:02:29,000 --> 00:02:32,990
would be 6, 7+3 would be 10.

36
00:02:33,000 --> 00:02:34,990
This is actually stepping by 4.

37
00:02:35,000 --> 00:02:37,990
It's starting at 3 and stepping by 4.

38
00:02:38,000 --> 00:02:42,990
So it would appear that I got those 2 swapped some place.

39
00:02:43,000 --> 00:02:45,990
So let's look at the code and see how this works.

40
00:02:46,000 --> 00:02:49,990
So we have numargs, which is the length of args.

41
00:02:50,000 --> 00:02:53,990
So that's the number of arguments that I am passing in and if numargs is

42
00:02:54,000 --> 00:02:58,990
less than one, we have a TypeError. If numargs equals to one, so I have three arguments.

43
00:02:59,000 --> 00:03:02,990
So let's just step down here to numargs equals three and so I

44
00:03:03,000 --> 00:03:04,990
assign them like this.

45
00:03:05,000 --> 00:03:06,990
Step, stop and start equals args.

46
00:03:07,000 --> 00:03:07,990
Well, that's not right.

47
00:03:08,000 --> 00:03:10,990
Its start, stop and step is what it should be.

48
00:03:11,000 --> 00:03:20,990
So I will switch those. Those got swapped just like I thought. start, stop and step.

49
00:03:21,000 --> 00:03:29,990
And that looks like it should fix it. I will save that and run it, and here we

50
00:03:30,000 --> 00:03:30,990
have a different result.

51
00:03:31,000 --> 00:03:32,990
Let's see if this looks right.

52
00:03:33,000 --> 00:03:33,990
It should start at 4.

53
00:03:34,000 --> 00:03:35,990
It is starting at 4.

54
00:03:36,000 --> 00:03:40,990
Stop at 25, that looks right, and the step is 3. So we have 4,

55
00:03:41,000 --> 00:03:44,990
7, 10, 13, 16, that looks right.

56
00:03:45,000 --> 00:03:48,990
So now it's working as we expected.

57
00:03:49,000 --> 00:03:53,990
At this point I would test the other ways of passing parameters, test some

58
00:03:54,000 --> 00:03:55,990
other corner cases.

59
00:03:56,000 --> 00:03:58,990
I happen to know because I made these errors that that's the extent of

60
00:03:59,000 --> 00:03:59,990
the errors in the file.

61
00:04:00,000 --> 00:04:04,990
So the trick is like so much of debugging to be patient, to follow the execution

62
00:04:05,000 --> 00:04:08,990
of the code, to look at what's supposed to happen that's not happening, to look

63
00:04:09,000 --> 00:04:12,990
at what's happening that's not supposed to happen, and through patience and

64
00:04:13,000 --> 00:04:17,990
perseverance to find those little typos, and really the key here is the

65
00:04:18,000 --> 00:04:18,990
patience and perseverance.

66
00:04:19,000 --> 00:04:29,000
Sometimes this can just take a while.

