1
00:00:01,270 --> 00:00:08,350
There are currently two bugs in our program, an easy to fix one and another one which is more challenging.

2
00:00:09,620 --> 00:00:12,260
Let me explain you the first bug.

3
00:00:12,470 --> 00:00:22,640
So when the user enters a to do such as add clean the bag and they enter another one and fix the draw

4
00:00:23,810 --> 00:00:29,330
and then show that to dos, we get these to dos next to each other.

5
00:00:31,880 --> 00:00:33,320
So how do you fix this?

6
00:00:33,350 --> 00:00:37,880
Well, there is no automated way you should use your reason.

7
00:00:38,570 --> 00:00:44,210
You should know as a programmer where in the code you are currently.

8
00:00:44,420 --> 00:00:47,720
So we are adding to DOS.

9
00:00:47,720 --> 00:00:55,220
That means the bug is probably in the if condition where we check for add.

10
00:00:57,140 --> 00:01:01,910
And this one is an easier one because we know that the problem here is the brake lines.

11
00:01:01,910 --> 00:01:05,810
So we are not adding any brake lines in here.

12
00:01:05,840 --> 00:01:09,800
Therefore, to do that, you need to go here and maybe plus.

13
00:01:11,750 --> 00:01:14,810
Backslash n and that will add a brake line.

14
00:01:16,800 --> 00:01:24,090
So just delete the existing to do save the file with control as we run.

15
00:01:25,590 --> 00:01:26,370
At.

16
00:01:26,400 --> 00:01:29,100
Clean the bag at.

17
00:01:30,820 --> 00:01:36,310
Fix the driver show and the bug is fixed.

18
00:01:36,970 --> 00:01:38,470
That was the first book.

19
00:01:38,500 --> 00:01:42,640
The other book, which is more challenging to fix, is this.

20
00:01:44,010 --> 00:01:49,890
Let's suppose the user wants to add the to the item add.

21
00:01:50,940 --> 00:01:52,260
A new member.

22
00:01:52,260 --> 00:01:57,990
So they will write, add and then add a new member.

23
00:01:59,160 --> 00:02:00,420
You press enter.

24
00:02:02,660 --> 00:02:06,110
You press show and you get this successfully.

25
00:02:06,110 --> 00:02:07,610
So far so good.

26
00:02:09,680 --> 00:02:17,030
But then if the user wants to add something and perhaps instead of answering a number, they don't know

27
00:02:17,030 --> 00:02:18,730
how to use the program well.

28
00:02:18,740 --> 00:02:29,540
So what they do is they enter something like add a new member, so they aim to edit the add a new member

29
00:02:30,020 --> 00:02:33,290
to do item and they press enter.

30
00:02:35,040 --> 00:02:39,900
And what will happen actually is that if you press show now.

31
00:02:43,190 --> 00:02:46,540
A new item was added.

32
00:02:46,550 --> 00:02:48,350
Add a new member.

33
00:02:50,350 --> 00:02:52,990
So as a new member was not edited.

34
00:02:55,040 --> 00:02:56,090
But what happened?

35
00:02:56,090 --> 00:02:56,740
Actually?

36
00:02:56,750 --> 00:02:58,850
Well, I'll explain you what happened.

37
00:02:59,060 --> 00:03:03,020
So when the user enters, it's at a new member.

38
00:03:03,650 --> 00:03:07,190
What happens is that the program starts to check.

39
00:03:08,140 --> 00:03:09,250
Line by line.

40
00:03:09,250 --> 00:03:17,800
So it checks if AD is in user action, and in this case, AD is actually in the user action.

41
00:03:19,000 --> 00:03:21,640
Well, it's part of a To-Do item.

42
00:03:22,960 --> 00:03:28,040
It was not meant to be sent as a command by the user.

43
00:03:28,060 --> 00:03:29,830
It was meant as a to do item.

44
00:03:29,830 --> 00:03:32,170
But the problem is not that smart.

45
00:03:33,780 --> 00:03:39,340
So the program was able to find an ad string in the user action.

46
00:03:39,360 --> 00:03:42,690
Therefore, what it did is it added.

47
00:03:43,840 --> 00:03:47,380
That's to do in the to do list.

48
00:03:48,370 --> 00:03:54,430
So actually what it did is it got the characters after the fourth character.

49
00:03:54,430 --> 00:03:57,910
So basically zero one, two, three.

50
00:03:58,910 --> 00:04:04,660
And so then it got to the space force of four is included and everything after four.

51
00:04:04,670 --> 00:04:09,200
So that was added as a new to do.

52
00:04:10,190 --> 00:04:14,420
So as you can see, we didn't get an error for this bug.

53
00:04:14,900 --> 00:04:20,420
So these kinds of bugs are not as easy to spot as the bugs which produce errors.

54
00:04:22,070 --> 00:04:30,950
Most likely you'd find this bug after the users report an issue and then you fix the bug and you release

55
00:04:31,850 --> 00:04:36,140
the next version of the software with the bug fixed.

56
00:04:37,610 --> 00:04:42,340
So knowing where the problem is could be 90% of the work.

57
00:04:42,350 --> 00:04:45,950
So now that we know it's easier to fix it, so how do we fix it?

58
00:04:45,980 --> 00:04:48,860
Well, again, we should use our reason.

59
00:04:48,860 --> 00:04:52,460
So it sounds like it's not a good idea to check.

60
00:04:53,380 --> 00:04:57,010
For an ad command anywhere in the string.

61
00:04:58,060 --> 00:05:02,050
So that checks if ad is anywhere in the string.

62
00:05:04,030 --> 00:05:20,470
So the user action was something like AD did add a new member and add in user action returns.

63
00:05:20,470 --> 00:05:21,160
True.

64
00:05:22,720 --> 00:05:26,380
So if true, this will be executed.

65
00:05:29,080 --> 00:05:41,380
A better way of thinking of implementing this is instead of doing that we do user action starts with.

66
00:05:44,170 --> 00:05:44,830
And.

67
00:05:45,790 --> 00:05:53,140
You press that you get false because user action does not start with ad.

68
00:05:54,700 --> 00:05:59,470
If you said user action starts with edit, then you get true.

69
00:06:00,340 --> 00:06:03,470
So starts with is a string method.

70
00:06:03,490 --> 00:06:09,400
So user action is pointing to a string and starts with is a string method.

71
00:06:09,400 --> 00:06:15,100
You can check that using str you will see that starts with a similar.

72
00:06:16,830 --> 00:06:17,880
Near the end.

73
00:06:19,820 --> 00:06:20,900
So here we go.

74
00:06:22,370 --> 00:06:30,710
So that method will check if a string starts with the input the argument value provides to the methods.

75
00:06:31,670 --> 00:06:42,620
Therefore, we go back to our program now and we say if user action starts with.

76
00:06:44,770 --> 00:06:55,750
And only in that case we extract the to do from the user action and we can do the same for the other

77
00:06:55,750 --> 00:06:56,560
conditions.

78
00:06:56,560 --> 00:07:03,820
So if user action starts with show.

79
00:07:07,880 --> 00:07:11,270
And I'll do the same for these other cases.

80
00:07:12,170 --> 00:07:13,190
Here we have.

81
00:07:13,400 --> 00:07:20,630
Edit Here we have complete.

82
00:07:25,550 --> 00:07:26,600
And here we have.

83
00:07:28,670 --> 00:07:29,330
Exit.

84
00:07:31,130 --> 00:07:39,080
So now our program is more explicit, it's more accurate, and let's have a run and check if everything

85
00:07:39,080 --> 00:07:40,010
is working well.

86
00:07:40,310 --> 00:07:51,770
So ad buy a camera show and if I press edit add a new member now.

87
00:07:54,500 --> 00:07:56,090
We're going to get this error.

88
00:07:57,200 --> 00:08:00,860
So an error is better than wrong output.

89
00:08:01,010 --> 00:08:12,110
So the error of this case in this case is that in line 26, we are trying to convert this object, which

90
00:08:12,110 --> 00:08:15,380
is a string because after edit we had.

91
00:08:18,290 --> 00:08:19,670
A string of.

92
00:08:20,720 --> 00:08:28,310
The program expects a number after added so the program has trouble converting that that string to a

93
00:08:28,310 --> 00:08:30,620
number using the end function.

94
00:08:34,330 --> 00:08:42,700
So while it is better to get an error as opposed to having wrong outputs, it is still not ideal.

95
00:08:43,770 --> 00:08:47,400
To just break the program like that for the user.

96
00:08:49,890 --> 00:08:56,010
So the user is going to get confused by this error you want to make.

97
00:08:57,070 --> 00:08:59,050
This more user friendly.

98
00:09:00,040 --> 00:09:09,310
And we can do that using error handling, not error handling is a technique which helps you as a programmer

99
00:09:09,310 --> 00:09:15,650
control the error messages and this is something we will do in the next videos.

100
00:09:15,670 --> 00:09:19,750
So instead of showing this error to the user, we will do something else.

101
00:09:20,600 --> 00:09:22,250
I'll teach you that in the next video.

102
00:09:22,280 --> 00:09:22,520
See you.

