There are currently two bugs in our program, an easy to fix one and another one which is more challenging.
Let me explain you the first bug.
So when the user enters a to do such as add clean the bag and they enter another one and fix the draw
and then show that to dos, we get these to dos next to each other.
So how do you fix this?
Well, there is no automated way you should use your reason.
You should know as a programmer where in the code you are currently.
So we are adding to DOS.
That means the bug is probably in the if condition where we check for add.
And this one is an easier one because we know that the problem here is the brake lines.
So we are not adding any brake lines in here.
Therefore, to do that, you need to go here and maybe plus.
Backslash n and that will add a brake line.
So just delete the existing to do save the file with control as we run.
At.
Clean the bag at.
Fix the driver show and the bug is fixed.
That was the first book.
The other book, which is more challenging to fix, is this.
Let's suppose the user wants to add the to the item add.
A new member.
So they will write, add and then add a new member.
You press enter.
You press show and you get this successfully.
So far so good.
But then if the user wants to add something and perhaps instead of answering a number, they don't know
how to use the program well.
So what they do is they enter something like add a new member, so they aim to edit the add a new member
to do item and they press enter.
And what will happen actually is that if you press show now.
A new item was added.
Add a new member.
So as a new member was not edited.
But what happened?
Actually?
Well, I'll explain you what happened.
So when the user enters, it's at a new member.
What happens is that the program starts to check.
Line by line.
So it checks if AD is in user action, and in this case, AD is actually in the user action.
Well, it's part of a To-Do item.
It was not meant to be sent as a command by the user.
It was meant as a to do item.
But the problem is not that smart.
So the program was able to find an ad string in the user action.
Therefore, what it did is it added.
That's to do in the to do list.
So actually what it did is it got the characters after the fourth character.
So basically zero one, two, three.
And so then it got to the space force of four is included and everything after four.
So that was added as a new to do.
So as you can see, we didn't get an error for this bug.
So these kinds of bugs are not as easy to spot as the bugs which produce errors.
Most likely you'd find this bug after the users report an issue and then you fix the bug and you release
the next version of the software with the bug fixed.
So knowing where the problem is could be 90% of the work.
So now that we know it's easier to fix it, so how do we fix it?
Well, again, we should use our reason.
So it sounds like it's not a good idea to check.
For an ad command anywhere in the string.
So that checks if ad is anywhere in the string.
So the user action was something like AD did add a new member and add in user action returns.
True.
So if true, this will be executed.
A better way of thinking of implementing this is instead of doing that we do user action starts with.
And.
You press that you get false because user action does not start with ad.
If you said user action starts with edit, then you get true.
So starts with is a string method.
So user action is pointing to a string and starts with is a string method.
You can check that using str you will see that starts with a similar.
Near the end.
So here we go.
So that method will check if a string starts with the input the argument value provides to the methods.
Therefore, we go back to our program now and we say if user action starts with.
And only in that case we extract the to do from the user action and we can do the same for the other
conditions.
So if user action starts with show.
And I'll do the same for these other cases.
Here we have.
Edit Here we have complete.
And here we have.
Exit.
So now our program is more explicit, it's more accurate, and let's have a run and check if everything
is working well.
So ad buy a camera show and if I press edit add a new member now.
We're going to get this error.
So an error is better than wrong output.
So the error of this case in this case is that in line 26, we are trying to convert this object, which
is a string because after edit we had.
A string of.
The program expects a number after added so the program has trouble converting that that string to a
number using the end function.
So while it is better to get an error as opposed to having wrong outputs, it is still not ideal.
To just break the program like that for the user.
So the user is going to get confused by this error you want to make.
This more user friendly.
And we can do that using error handling, not error handling is a technique which helps you as a programmer
control the error messages and this is something we will do in the next videos.
So instead of showing this error to the user, we will do something else.
I'll teach you that in the next video.
See you.