1 00:00:00,310 --> 00:00:02,070 All right, so what's next? 2 00:00:02,070 --> 00:00:03,930 Let's get that list created. 3 00:00:03,930 --> 00:00:05,820 I'm gonna pull over this. 4 00:00:05,820 --> 00:00:08,130 As a user, I should be able to add an item to a list. 5 00:00:08,130 --> 00:00:10,550 Let's do it. 6 00:00:13,310 --> 00:00:18,697 So in our shopping list here I think right out of the gate, 7 00:00:18,697 --> 00:00:24,100 we should Create a new empty list named shopping_list. 8 00:00:24,100 --> 00:00:25,347 Let's do that. 9 00:00:25,347 --> 00:00:30,351 You know how to do that and then after we make 10 00:00:30,351 --> 00:00:35,786 that new list, we should make a new function. 11 00:00:35,786 --> 00:00:42,990 We should Create the function named add_to_list that declares a parameter, 12 00:00:48,194 --> 00:00:51,910 Named item. 13 00:00:51,910 --> 00:00:59,360 And then inside the body of that just go ahead and say Add the item to the list. 14 00:01:01,060 --> 00:01:07,324 Awesome, and then finally let's go in and we'll call that function right about here. 15 00:01:07,324 --> 00:01:09,080 We'll go down here. 16 00:01:09,080 --> 00:01:14,930 We'll call that function, so we'll say Call add_to_list 17 00:01:14,930 --> 00:01:19,815 with new_item as an argument. 18 00:01:19,815 --> 00:01:22,200 All right, that make sense? 19 00:01:22,200 --> 00:01:26,136 We're going to come up here, create an empty list, we'll create a function, 20 00:01:26,136 --> 00:01:27,739 we'll add the item to the list. 21 00:01:27,739 --> 00:01:28,790 Makes sense, right? 22 00:01:29,840 --> 00:01:30,770 You got this. 23 00:01:30,770 --> 00:01:35,670 So here, get ready to pause me and you give those a go, one at a time. 24 00:01:35,670 --> 00:01:39,090 Then I'll let you know before I start the next one if you wanna peek after 25 00:01:39,090 --> 00:01:39,660 each step. 26 00:01:39,660 --> 00:01:42,830 But I know you can do this, ready? 27 00:01:42,830 --> 00:01:44,220 Pause me. 28 00:01:44,220 --> 00:01:45,360 So how'd you do? 29 00:01:45,360 --> 00:01:47,361 So creating an empty list looks like this. 30 00:01:47,361 --> 00:01:53,440 You say shopping_list = []. 31 00:01:53,440 --> 00:01:55,940 All right, and now for the function. 32 00:01:55,940 --> 00:02:01,318 So we are going to define a new function named add_to_list. 33 00:02:01,318 --> 00:02:04,790 And it declares a parameter name item. 34 00:02:04,790 --> 00:02:08,160 So there we are and there's a colon to get to the body. 35 00:02:08,160 --> 00:02:11,140 I'm gonna add the item to our list. 36 00:02:11,140 --> 00:02:15,042 So to add to the end of a list, you append, right? 37 00:02:15,042 --> 00:02:21,727 So we're gonna say shopping_list.append and we're gonna pass in that item. 38 00:02:21,727 --> 00:02:24,459 Awesome, and finally, let's call it. 39 00:02:24,459 --> 00:02:31,820 So we will say down here, let's call that add_to_list. 40 00:02:31,820 --> 00:02:35,571 Basically, anything that's come through here, and made it down this far, 41 00:02:35,571 --> 00:02:37,370 we're just gonna add it to the list. 42 00:02:37,370 --> 00:02:41,270 Sounds good, and since we are doing of all of our checks here, 43 00:02:41,270 --> 00:02:42,924 we've got a thing set up. 44 00:02:42,924 --> 00:02:46,980 We're pretty much protected from commands making their way through. 45 00:02:46,980 --> 00:02:51,819 As long as we are diligent about using break and continue, 46 00:02:51,819 --> 00:02:54,500 this will only be proper items. 47 00:02:54,500 --> 00:02:58,245 It seems like it's working, but we don't have a way of showing the list just yet. 48 00:02:58,245 --> 00:02:59,189 But let's see, 49 00:02:59,189 --> 00:03:03,180 is there something else on the board we can tackle before we get there? 50 00:03:03,180 --> 00:03:08,093 As a user, upon adding an item to a list, I should know the total length of my list, 51 00:03:08,093 --> 00:03:10,340 so that I don't go buy. 52 00:03:10,340 --> 00:03:11,280 Boy, I didn't edit that very good. 53 00:03:11,280 --> 00:03:14,310 I don't over buy is what I want that to say. 54 00:03:14,310 --> 00:03:20,517 So that I don't over buy, this is important part of the communication there. 55 00:03:20,517 --> 00:03:23,550 So that I don't overpurchase is probably a better word than that even. 56 00:03:23,550 --> 00:03:26,450 All right, so as a user, upon adding an item to a list, I should know the total 57 00:03:26,450 --> 00:03:29,280 length of the list so that you're there's a 100 list things on this. 58 00:03:29,280 --> 00:03:29,907 We don't want that. 59 00:03:29,907 --> 00:03:31,870 So let's do that. 60 00:03:31,870 --> 00:03:35,340 So let's just put that in the add_to_list, right? 61 00:03:35,340 --> 00:03:38,580 If we come in here, right about here, right? 62 00:03:38,580 --> 00:03:44,022 Don't you think? So we'll say Notify the user that the item 63 00:03:44,022 --> 00:03:52,353 was added, and state the number of items in the list currently. 64 00:03:52,353 --> 00:03:58,685 We don't want them to over buy, [LAUGH] over purchase, got it? 65 00:03:58,685 --> 00:04:01,990 All right, pause me, go for it. 66 00:04:01,990 --> 00:04:03,020 How'd you do? 67 00:04:03,020 --> 00:04:03,520 Here's how I did. 68 00:04:03,520 --> 00:04:05,340 So I said print. 69 00:04:05,340 --> 00:04:08,850 And then I said Added: List has {} items. 70 00:04:12,552 --> 00:04:19,486 Format and we are going to get the number of items by passing it to len. 71 00:04:19,486 --> 00:04:21,445 Here we go. 72 00:04:21,445 --> 00:04:23,890 Did I close them all out? 73 00:04:23,890 --> 00:04:25,490 There we go. 74 00:04:25,490 --> 00:04:27,920 Awesome, so let's give that a run. 75 00:04:27,920 --> 00:04:31,210 We'll say python shopping_list. 76 00:04:31,210 --> 00:04:33,220 And I wanna pick up some apples. 77 00:04:33,220 --> 00:04:37,900 1 items, a common bug. 78 00:04:37,900 --> 00:04:41,670 And we'll do bananas, and now we can forget about it because we got 2 items, 79 00:04:41,670 --> 00:04:42,196 awesome. 80 00:04:42,196 --> 00:04:47,380 But the items are adding, so I think we've got some tickets to complete, don't you? 81 00:04:47,380 --> 00:04:49,610 So I should be able to add items to list. 82 00:04:49,610 --> 00:04:51,520 Let's go ahead and do that. 83 00:04:51,520 --> 00:04:54,555 And as a user, upon adding an item, we know how many are there now. 84 00:04:55,735 --> 00:05:00,615 Awesome, and I'm gonna type DONE because I can, DONE. 85 00:05:00,615 --> 00:05:04,395 Let's knock out those last few issues right after this quick break.