#100DaysOfCode in Python Transcripts
Chapter: Days 88-90: Home Inventory App
Lecture: Bug and functionality fixes
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So while the app actually does work
0:03
there are quite a few things that we've left out.
0:05
And I've done this on purpose because this is what I'd
0:08
like you to work on for your Day 3.
0:11
If not, just work on to expanded just for fun.
0:14
You can do it after your 100 days is up,
0:15
whatever you feel like.
0:17
Or maybe you can use it as an idea
0:19
to factor it into your own inventory app.
0:22
This first thing is,
0:24
is that we haven't actually captured incorrect input.
0:29
We have here.
0:30
So for example, if we're at the main menu
0:32
we put the letter a.
0:34
We just get invalid option, try again.
0:37
Even if we do something like 11.
0:39
We know it's a number but it doesn't
0:41
match any of these, so we get invalid option try again.
0:45
Now what happens if we add a room?
0:48
Now we know we have kitchen in there.
0:50
But if we add kitchen again, what happens?
0:54
Kitchen already exists.
0:56
So we need to be able to capture that.
0:58
What happens if someone wants to add multiple bedrooms
1:02
but they just want to call it bedroom.
1:05
It's a silly scenario because can't think of anyone who'd
1:08
do that but this is something that needs to be captured.
1:11
Rather than allowing an error to just suddenly pop up
1:14
and then exit out of the app.
1:17
So there's one.
1:19
Adding multiple rooms can cause a problem.
1:22
So, see if you can figure out a way to capture that.
1:26
Now that we have that,
1:29
let's see if we can add duplicate items.
1:32
So we'll add a knife for $20.
1:38
Let's try and add another knife for $20.
1:41
And that works.
1:42
So why does that work?
1:43
Well that actually works because SQLite has its own
1:47
sort of tagging behind the scenes.
1:49
It tags each entry with its own id.
1:53
So you can have duplicates items below a table name.
1:58
You can't have duplicate table names though.
2:01
Now is that a problem?
2:02
For me i don't think it is a problem.
2:04
But if you wanted to capture that you could.
2:07
That's something to capture.
2:09
But what about this?
2:12
Let's say we want to add a microwave,
2:17
but by accident instead of hitting $20 we hit 2o.
2:24
We've entered in a letter instead of a number.
2:29
What's going to happen?
2:30
It allowed it didn't it?
2:31
So it allowed the fact that we had a letter and a
2:35
number in there.
2:36
Which is wrong,
2:38
so if you actually pull up our
2:40
SQLite database in SQLite viewer.
2:42
Which I have done here.
2:44
You can see we now have values
2:48
but microwave is now accepted to O.
2:53
So what we'll do now
2:55
by allowing this to happen,
2:57
we've probably caused problems here.
2:59
So view inventory list, let's do kitchen.
3:04
There we go, it failed because
3:06
it needs it formatted as a number not a string.
3:11
This is for the actual value calculation.
3:15
So it was able to print it all out.
3:17
Once it got to the actual calculation for the total value,
3:21
didn't like it.
3:22
Same thing for actually printing out
3:24
microwave and its value.
3:27
So that's something we screwed up and we'd actually,
3:29
in that case we actually broken the application completely
3:33
because we have no way in here to code a deletion.
3:36
Which again is something you could do.
3:38
So I'm going to go manually into the database here.
3:42
And we'll delete this record
3:47
because it's going to cause us problems.
3:50
I'll demonstrate that again.
3:51
This time we'll add an item to the inventory.
3:54
We'll choose the room study.
3:58
Study.
3:59
And then let's add ourselves a chair.
4:02
And instead of actually entering a number at all.
4:05
Let's just use the word water.
4:07
And you can see it actually returned
4:09
and we were able to add it successfully to the table.
4:11
So again, that's going to cause us issues
4:14
and we'll have to delete it manually from the database.
4:17
We can also capture different errors to do with launching
4:20
the app as we saw.
4:22
I've only got this sampler here but we can actually put
4:24
some more scenarios in there if you wanted.
4:28
That's something you could work on.
4:30
And the last thing here is, check this out.
4:35
We just entered an empty room.
4:38
A room with name space has been added to the database.
4:43
That's a problem, so.
4:45
That's something we need to capture as well.
4:48
This is all stuff you can work towards.
4:50
If you get bored and if you want to work towards it.
4:52
But you can see that this is all stuff,
4:55
if you're creating an app that you have to take
4:58
into account.
4:59
And just one other thing as well that is rubbing me
5:02
the wrong way.
5:03
Is this elif tree here.
5:06
I don't like that, I've done it
5:08
just for demonstration purposes but essentially
5:11
you would preferably throw all of these into a dictionary
5:16
and make it a bit more Pythonic.
5:19
There's no need for it to be this large.
5:21
But either way, this is your little go to points to
5:24
see if you can expand on this and improve it.
5:27
If you wish.
5:28
You might even just think about writing this app
5:30
yourself in a way that you see fit.
5:33
And covering these problems as you build it.
5:37
So have fun.