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


Talk Python's Mastodon Michael Kennedy's Mastodon