#100DaysOfCode in Python Transcripts
Chapter: Days 88-90: Home Inventory App
Lecture: Writing and working the main menu

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Okay, so the first thing we're going to look at is pretty much how you get started. It's a bit daunting, looking at an empty page like this, isn't it?
0:11 The best way I find to start is to actually think about what you want your app to do, and make a menu for yourself.
0:18 And normally I would say storyboard it, you know, get an empty document, draw it out with a piece of paper and a pen, whatever.
0:25 But I think given this is a very basic app, I think this works quite simply, quite easily, to just create a menu.
0:35 Okay? It's just going to be text based like an old CLI app that has 1, 2, 3, 4, 5 with your different options, okay?
0:42 So, without actually showing you the code, again I'm not going to show you the code until the end,
0:48 but it is in the repo if you want to have a peek, of course. I'm just going to create under a main menu function, let me just copy and paste it in,
0:59 just going to create a list, okay? Now this is a dictionary with the menu options in there, okay, and we're creating this with Add Room, Add Inventory,
1:12 View Inventory List, Total Value, and Exit. So these are the five things we want our app to do, okay, so the idea is when the app launches
1:22 it's going to give you the option to add a room 'cause we're going to add a room to add inventory to.
1:29 So you got to think about it in that sort of a way, alright. Sequentially, if you want to use this app,
1:35 you're going to add the room first because by default we don't have a room to add anything to, okay? Once we have a room,
1:42 then we can actually add some inventory, and then once we have inventory in there against a room, then we can actually view it.
1:53 And then again, once we have everything in there we can see what the total value per room is, or the total value for the entire house so to speak,
2:04 and then we can exit. And that's what we're going to wrap our entire app around today and tomorrow and the day after.
2:12 Now, again, I'm not going to show you the entire app and walk you through every single function just yet,
2:18 I'm just going to show you the more critical points, the more technical points, okay? So to make this menu, I've decided to put it in a while loop.
2:29 I'm just going to copy and paste it in rather than make you watch me type it all out, there we go. So we have a while loop here, while true,
2:38 so this is always going to happen, this list is always going to come up on the screen, unless something else is happening,
2:46 it's going to come back to this list. So we know with the dictionary that unless you sort it first it's not always going to print in order
2:58 from 1-2-3-4-5 when you iterate over it. So what I've done here is I've said for the item and for the description in our sorted menu,
3:13 okay the items in there but sorted, we're going to print the item and the description, we're going to print that and that.
3:20 And this little for loop here allows us to print this menu on screen, and it allows it to print it in order, that's what sorted is there for.
3:30 And then we take the user input, so if the user selects one we're going to call a function called Add Room,
3:39 if they select two, we're going to do Add Inventory, I'll explain this in just a second, if they do three, View Inventory, four Calculate the Total,
3:49 five sys.exit. Now for sys.exit to work, we have to import sys and this sys.exit just exits out of the program,
4:03 and if anything else is entered: invalid option, try again. Now the Check Input function here that is being called
4:12 by Add Inventory and View Inventory is a little function I wrote just to check whether the room exists. So if you're going to add inventory,
4:23 the first thing you need to know is what room you're adding the inventory to, right? Well that's what this checks here.
4:31 So I'll quickly copy and paste that in again for you to have a look at. Lets just pop down here. Okay, so here's Check Input.
4:41 So the first thing we're doing is we're actually printing out a list of the rooms, so this is yet another function,
4:49 don't worry you'll see it all in the final code, but it's essentially listing out the rooms that we have and it'll printed on the screen,
4:56 which allows the user to see what room they want to select. And then the user types in the room, gets converted to lower case,
5:06 and then if the room, which is assigned to selection, if it does not exist in the list of rooms then you get the message: that room does not exist.
5:20 Else, we return the selection. Don't worry about what scrub is, we'll cover that on another video. And that's it, okay. So then, once we have the room
5:32 we add inventory to that room. So all of these functions will be available in the final code, but what I'd like you to do is start thinking about
5:42 how you would write these functions. How would you write Add Room? How would you write Add Inventory? How would you write View Inventory?
5:51 Okay, and that's it for this one. In the next video we're going to look at some more of the advanced calls in this program and just for now, again,
6:03 think about how you would write these different.

Talk Python's Mastodon Michael Kennedy's Mastodon