1 00:00:00,600 --> 00:00:05,280 Okay, first thing's first, I'm gonna wipe our all these instructional columns. 2 00:00:05,280 --> 00:00:08,800 Let's get rid of all of these, clean that up a bit. 3 00:00:08,800 --> 00:00:11,480 Let's get a little noisy. 4 00:00:11,480 --> 00:00:13,230 All right, awesome. 5 00:00:13,230 --> 00:00:15,620 So, that feels better. 6 00:00:15,620 --> 00:00:18,042 Let's look at what we have left. 7 00:00:18,042 --> 00:00:21,300 All right so we left done here because we want to print the list out in 8 00:00:21,300 --> 00:00:22,162 totality when it's done. 9 00:00:22,162 --> 00:00:25,370 We wanna show the list and there's this one here too. 10 00:00:25,370 --> 00:00:28,740 I wanna see the list any time so I can verify my order. 11 00:00:28,740 --> 00:00:31,250 So let's make a new command for that. 12 00:00:31,250 --> 00:00:32,320 That sounds good, all right? 13 00:00:32,320 --> 00:00:33,970 So let's come back over here. 14 00:00:33,970 --> 00:00:36,930 So first, I'm gonna clean this up a little bit. 15 00:00:36,930 --> 00:00:41,510 I'm gonna move this add to list down below the show help and 16 00:00:41,510 --> 00:00:44,550 typically what happens in between functions, 17 00:00:44,550 --> 00:00:48,220 you'll see that the starts getting busy is you leave two spaces. 18 00:00:48,220 --> 00:00:52,820 So there we, so we left that two spaces between the two there. 19 00:00:52,820 --> 00:00:55,060 Before and after, there you go. 20 00:00:55,060 --> 00:01:03,250 All right, so we want to define a new function that's named show list. 21 00:01:03,250 --> 00:01:03,970 So let's do that. 22 00:01:03,970 --> 00:01:10,049 So we'll say, define a function 23 00:01:10,049 --> 00:01:15,478 named show_list that prints 24 00:01:15,478 --> 00:01:20,260 all the items in the list. 25 00:01:21,750 --> 00:01:23,200 That sounds good, right? 26 00:01:23,200 --> 00:01:24,680 You got this, right? 27 00:01:24,680 --> 00:01:27,380 You can loop through all of them and print them out, right? 28 00:01:27,380 --> 00:01:28,960 You got this, ready? 29 00:01:28,960 --> 00:01:31,700 Pause me. How did it go? 30 00:01:31,700 --> 00:01:32,700 Here's how I did it. 31 00:01:32,700 --> 00:01:36,014 So I said def show list. 32 00:01:40,551 --> 00:01:45,620 Here's your list, nice little heading there for it. 33 00:01:45,620 --> 00:01:48,090 And we're gonna loop through that list. 34 00:01:48,090 --> 00:01:55,500 So for each of the items In the shopping list, we are going to print said item. 35 00:01:56,810 --> 00:02:04,780 Awesome, and now, we want to be able to have this called. 36 00:02:04,780 --> 00:02:08,100 So let's make the command SHOW, in all upper case. 37 00:02:08,100 --> 00:02:09,628 So let's put it right here. 38 00:02:09,628 --> 00:02:16,300 We'll say Enable the SHOW command, 39 00:02:16,300 --> 00:02:20,315 cuz we wanna call that function SHOW command to show the list. 40 00:02:22,540 --> 00:02:25,360 Don't forget to update the help documentation. 41 00:02:26,930 --> 00:02:27,710 This is super important. 42 00:02:27,710 --> 00:02:29,480 Sometimes you'll add a new command and 43 00:02:29,480 --> 00:02:31,370 you'll forget that you've already made this help. 44 00:02:31,370 --> 00:02:35,380 And we have the help at the top of the file, so don't forget to do that and 45 00:02:35,380 --> 00:02:38,070 I wanna drop a hint here for you. 46 00:02:38,070 --> 00:02:41,280 Make sure to run it. 47 00:02:41,280 --> 00:02:44,790 Make sure that you run this after you had that show command. 48 00:02:44,790 --> 00:02:46,970 There's a little gotcha if you forget something. 49 00:02:46,970 --> 00:02:50,170 So make sure you run it, and just make sure your list looks right. 50 00:02:50,170 --> 00:02:50,880 Are you ready? 51 00:02:50,880 --> 00:02:52,180 Pause me. 52 00:02:52,180 --> 00:02:53,200 Did you catch it? 53 00:02:53,200 --> 00:02:54,640 Here's what I did. 54 00:02:54,640 --> 00:02:57,940 So I went ahead and it's another else if. 55 00:02:57,940 --> 00:03:04,070 And if this is equal to our command of show, we call the function. 56 00:03:05,510 --> 00:03:09,642 But we got to remember to use our control flow, right? 57 00:03:09,642 --> 00:03:11,310 We gotta call continue and 58 00:03:11,310 --> 00:03:16,100 if not, what will happen is show will end up in your grocery list. 59 00:03:16,100 --> 00:03:18,650 When you embrace flow control like break and continue, 60 00:03:18,650 --> 00:03:21,740 it's super important that you pay attention to all the used cases. 61 00:03:21,740 --> 00:03:24,630 All right, we are so close to done. 62 00:03:24,630 --> 00:03:27,970 Now, we need to show the list on completion. 63 00:03:27,970 --> 00:03:32,060 So what we can do is when this while loop is over while this while true when 64 00:03:32,060 --> 00:03:32,700 this is over. 65 00:03:34,000 --> 00:03:34,660 We can just call it. 66 00:03:38,026 --> 00:03:43,300 We will call show_list. 67 00:03:43,300 --> 00:03:45,820 Awesome let's give that a run. 68 00:03:45,820 --> 00:03:51,700 Let's say, Python shopping list. 69 00:03:55,150 --> 00:03:57,330 Look what I forgot to do. 70 00:03:57,330 --> 00:03:59,740 I didn't update the help, so I don't know about show. 71 00:03:59,740 --> 00:04:00,340 I'm gonna do that. 72 00:04:00,340 --> 00:04:01,750 Let me get back up in there. 73 00:04:01,750 --> 00:04:03,000 Let's go back up in here. 74 00:04:04,220 --> 00:04:08,890 So we'll add enter SHOW 75 00:04:11,270 --> 00:04:15,300 to see your current list. 76 00:04:15,300 --> 00:04:17,610 Awesome, whew that was close. 77 00:04:18,930 --> 00:04:22,920 Okay so we're gonna run Python shopping_list.py. 78 00:04:24,600 --> 00:04:28,030 There's the show which we pick up at the store. 79 00:04:29,450 --> 00:04:31,590 Well obviously we need some tortillas. 80 00:04:33,370 --> 00:04:35,190 Let's get some green chiles. 81 00:04:38,620 --> 00:04:39,540 I need pork shoulder. 82 00:04:41,980 --> 00:04:42,950 What am I forgetting? 83 00:04:42,950 --> 00:04:44,370 What's on my list again? 84 00:04:44,370 --> 00:04:46,480 What do I have here? 85 00:04:46,480 --> 00:04:49,870 Right, tortillas, green chiles, pork shoulders, cilantro. 86 00:04:52,400 --> 00:04:54,770 There we go and now I am DONE. 87 00:04:54,770 --> 00:04:57,835 And check it out there is my final list, 88 00:04:57,835 --> 00:05:01,710 you're totally invited to my taco fiesta, look at this. 89 00:05:01,710 --> 00:05:05,981 We are all done, awesome. 90 00:05:06,990 --> 00:05:09,080 Should we walk it one more time? 91 00:05:09,080 --> 00:05:10,220 Let's do that. So I'm gonna come in here. 92 00:05:10,220 --> 00:05:14,290 I'm gonna get rid of these instructional commands that we have in here. 93 00:05:16,850 --> 00:05:18,070 Let's just walk it. 94 00:05:18,070 --> 00:05:24,740 So we create our brand new list that the program will use in a global fashion. 95 00:05:24,740 --> 00:05:28,130 And then our program is gonna accept multiple commands. 96 00:05:28,130 --> 00:05:30,140 So we should have some detailed help, right? 97 00:05:30,140 --> 00:05:32,548 Programs are no good if users can't use them. 98 00:05:32,548 --> 00:05:38,210 So we print out our help, and then we have our add to list function. 99 00:05:38,210 --> 00:05:41,850 And it appends a value to the end of our shopping list and 100 00:05:41,850 --> 00:05:45,140 updates the user with the count. 101 00:05:45,140 --> 00:05:46,970 And lists and most objects for 102 00:05:46,970 --> 00:05:51,260 that matter can make use of the len command, so pythonic. 103 00:05:52,350 --> 00:05:57,212 And then we have our show list, and lists are iterable, 104 00:05:57,212 --> 00:06:01,690 so we can loop through them with a for item in list. 105 00:06:01,690 --> 00:06:05,170 Now, this is kind of strange, right? 106 00:06:05,170 --> 00:06:07,540 So we have this while True. 107 00:06:07,540 --> 00:06:10,610 One way to write loop that take many flows is to set things up 108 00:06:10,610 --> 00:06:12,500 in an infinite loop matter. 109 00:06:12,500 --> 00:06:14,660 While true is always gonna happen, 110 00:06:14,660 --> 00:06:19,100 we rely on further control flow to control how things happen. 111 00:06:20,230 --> 00:06:24,390 We take a single prompt and since it can be an item or 112 00:06:24,390 --> 00:06:27,600 a command, we have made the prompt generic. 113 00:06:27,600 --> 00:06:30,570 A little greater than sign, feels kinda good. 114 00:06:30,570 --> 00:06:33,210 And then we just check each of our commands. 115 00:06:33,210 --> 00:06:36,650 So here's the flow if the user is done. 116 00:06:38,120 --> 00:06:41,460 Break out of the while loop, we are done with this while loop, 117 00:06:41,460 --> 00:06:44,090 we don't anything more to do so break out of it. 118 00:06:44,090 --> 00:06:50,390 Otherwise if we're looking for help, show it and remember to control the flow. 119 00:06:51,510 --> 00:06:56,660 Calling continue will shoot us back up to this while true line which is no surprise, 120 00:06:56,660 --> 00:06:58,030 still true. 121 00:06:58,030 --> 00:07:02,350 What this avoids is us from continuing and adding help to our grocery list. 122 00:07:02,350 --> 00:07:03,510 We don't want that. 123 00:07:03,510 --> 00:07:05,560 Well, at least not from the grocery store. 124 00:07:05,560 --> 00:07:10,440 Now, I of course, could have just put this add to list inside of an else and we could 125 00:07:10,440 --> 00:07:14,360 remove the continues, but then I would've been able to show you the continue loop. 126 00:07:14,360 --> 00:07:18,890 So I want you to be cautious of controlling the flow with break and 127 00:07:18,890 --> 00:07:19,930 continue. 128 00:07:19,930 --> 00:07:21,670 Break is known to break your program, 129 00:07:21,670 --> 00:07:26,650 and then finally we add that new item to our function. 130 00:07:26,650 --> 00:07:29,810 It comes into the add to list then boom, here we go. 131 00:07:29,810 --> 00:07:32,370 So I hope that that all made sense, and 132 00:07:32,370 --> 00:07:36,950 if there is anything at all that is still confusing you, feel free, rewind it, 133 00:07:36,950 --> 00:07:40,740 watch it again and hit the forum if there's anything confusing at all. 134 00:07:40,740 --> 00:07:43,060 You did an awesome job, enjoy the taco party.