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