1 00:00:00,470 --> 00:00:01,050 All right. 2 00:00:01,850 --> 00:00:07,430 Your head must be spinning because of all these looping, that's that's a really bad joke. 3 00:00:07,430 --> 00:00:11,570 But I thought it was funny because I've been recording for hours now and I think I'm going a little 4 00:00:11,570 --> 00:00:11,990 kooky. 5 00:00:11,990 --> 00:00:17,330 So this is going to be my last video for the day now forth, of course, but we're going to do a little 6 00:00:17,330 --> 00:00:19,370 fun exercise now. 7 00:00:19,370 --> 00:00:21,080 I call all exercise is fun. 8 00:00:21,300 --> 00:00:25,030 Obviously I'm biased, but this one, this one's especially fun. 9 00:00:25,610 --> 00:00:26,540 Why are we going to do. 10 00:00:27,560 --> 00:00:34,640 Well, we're going to simulate what a computer does when when we have something like a graphical user 11 00:00:34,640 --> 00:00:40,220 interface that is a computer is able to display, let's say, even an image over here. 12 00:00:40,220 --> 00:00:40,470 Right. 13 00:00:40,490 --> 00:00:42,170 I can see the robot over here. 14 00:00:42,770 --> 00:00:43,890 I can see the mouse. 15 00:00:44,450 --> 00:00:46,400 This is a graphical user interface. 16 00:00:46,410 --> 00:00:47,210 I see pictures. 17 00:00:47,210 --> 00:00:52,420 I see images on my screen, these pixels on my screen, and I can control them. 18 00:00:53,060 --> 00:01:00,530 Well, we're going to create a basic version of this to show you how a computer would work just from 19 00:01:00,530 --> 00:01:05,360 the stuff that we've learned up until now, using loops and using conditional logic. 20 00:01:05,540 --> 00:01:06,950 So what are we going to do? 21 00:01:08,120 --> 00:01:16,100 Well, this is the exercise and you can check out the Reppel here or you can recreate this or again 22 00:01:16,100 --> 00:01:21,480 in this video, you should have resources attached that you can play with it yourself. 23 00:01:22,220 --> 00:01:27,410 And what I want you to do is I want you to loop through this list of lists. 24 00:01:27,950 --> 00:01:35,630 And every time you encounter a zero, I want you to display on the screen over here an empty space. 25 00:01:37,140 --> 00:01:43,300 Because a zero in a computer denotes nothing, right, we want a blank on the screen. 26 00:01:43,770 --> 00:01:51,390 However, when I see one, I want to simulate a pixel right that tiny, tiny dot on our computers that 27 00:01:51,390 --> 00:01:52,540 can be full of colors. 28 00:01:52,560 --> 00:01:53,190 It could be green. 29 00:01:53,190 --> 00:01:53,790 It can be blue. 30 00:01:53,790 --> 00:01:54,630 It can be orange. 31 00:01:55,140 --> 00:01:58,110 But for our case, I wanted to be a star. 32 00:01:58,290 --> 00:02:05,460 And using that, I want you to create a program that takes this picture that let's say is in our database 33 00:02:05,460 --> 00:02:12,680 or in our computers hard drive and displays it on the screen using space or multiply. 34 00:02:12,960 --> 00:02:19,420 And all I want you to do is when I click run, I want you to display that image right here. 35 00:02:20,250 --> 00:02:20,700 All right. 36 00:02:20,730 --> 00:02:24,240 This is a little tough one, and I'm kind of letting you figure out on your own. 37 00:02:24,240 --> 00:02:27,810 But trust me, you've learned all the tools necessary to do this. 38 00:02:28,530 --> 00:02:28,980 Pausa. 39 00:02:28,980 --> 00:02:29,430 Video. 40 00:02:29,730 --> 00:02:30,360 Give it a go. 41 00:02:30,810 --> 00:02:32,730 Otherwise, I'm going to show you how it's done. 42 00:02:34,190 --> 00:02:38,570 So the very first thing I like to do is to think about what I'm about to do. 43 00:02:38,960 --> 00:02:40,730 I want to make sure that we have a plan in mind. 44 00:02:40,940 --> 00:02:47,000 So I'm going to comment first and I'm going to say, well, we definitely want to iterate over picture. 45 00:02:48,360 --> 00:02:53,490 Right, so we're going to do some sort of iteration here, so that's number one. 46 00:02:55,410 --> 00:03:06,450 And then in here, I want to say that if it's a zero, then I want to print an empty space. 47 00:03:07,860 --> 00:03:11,100 And if it's a one. 48 00:03:17,450 --> 00:03:18,830 All right, so that's the plan. 49 00:03:19,610 --> 00:03:27,440 OK, so this shouldn't be too hard, actually, before you get started, in order for this to work, 50 00:03:27,950 --> 00:03:35,480 you need to Google a special parameter or special option that you can give the print function. 51 00:03:35,840 --> 00:03:41,540 And as a matter of fact, the print function that you need to add or the option that you need to add 52 00:03:41,540 --> 00:03:42,620 is this and. 53 00:03:43,900 --> 00:03:50,830 Option, and if we scroll down, it doesn't display it that well, but you can see here string appended 54 00:03:50,830 --> 00:03:51,990 after the last value. 55 00:03:52,840 --> 00:03:56,640 So the default when we print something is a new line. 56 00:03:56,680 --> 00:04:00,230 But ideally, we might not want a new line. 57 00:04:00,610 --> 00:04:03,760 So when that happens, you might have to use this and. 58 00:04:04,800 --> 00:04:11,360 Option now I know I left it really vague, I want to I want you to practice Googling this and and figuring 59 00:04:11,370 --> 00:04:16,590 out from your mistake you're going to have a bug when you create this code, when you try to display 60 00:04:16,860 --> 00:04:23,190 this information, but try to solve it using the tools that you have of problem solving. 61 00:04:24,170 --> 00:04:26,000 All right, enough talk, let's get to it. 62 00:04:27,130 --> 00:04:35,740 So the first thing I want to do is iterate over the picture, I'm going to say for image in picture 63 00:04:36,430 --> 00:04:40,310 because, well, this is one picture right here. 64 00:04:40,960 --> 00:04:45,970 So this is the picture, but it's inside of a list because we can have multiple pictures. 65 00:04:46,540 --> 00:04:52,480 And then I'm going to loop once again over this individual list. 66 00:04:52,490 --> 00:04:55,240 So once again, I need to do a for loop. 67 00:04:55,240 --> 00:04:59,830 And this time I'm going to say four pixel because each one of this is a pixel. 68 00:05:00,840 --> 00:05:05,160 In the image, so this is a nested for loop. 69 00:05:06,040 --> 00:05:09,220 Now, I'm going to add a conditional and say if. 70 00:05:12,180 --> 00:05:13,680 Equals one. 71 00:05:14,530 --> 00:05:15,960 Then I'm going to. 72 00:05:18,940 --> 00:05:20,080 A star. 73 00:05:24,440 --> 00:05:25,220 Otherwise. 74 00:05:27,990 --> 00:05:29,070 I'm going to print. 75 00:05:31,230 --> 00:05:32,800 An empty string. 76 00:05:33,270 --> 00:05:40,870 Well, maybe not empty, right, because we do want a space, a blank space in the image. 77 00:05:41,940 --> 00:05:42,210 All right. 78 00:05:42,210 --> 00:05:44,600 So let's see if this works. 79 00:05:46,130 --> 00:05:47,450 If I click, run. 80 00:05:50,030 --> 00:05:51,530 That's not really why I wanted. 81 00:05:52,750 --> 00:06:00,790 I want a clear image here, but I'm just getting things one in line and remember, this was the little 82 00:06:00,790 --> 00:06:05,950 trick where a print, every time it prints, it creates a new line. 83 00:06:07,630 --> 00:06:12,340 The default, again, if we close this, you'll see. 84 00:06:13,430 --> 00:06:21,530 Is that end equals to this escape sequence of new line, so we can change that by simply saying. 85 00:06:22,720 --> 00:06:29,800 Star, comma, and and then I'm going to say for the end, I don't want a new line, I just want. 86 00:06:30,070 --> 00:06:33,370 Well, a string but an empty string. 87 00:06:34,490 --> 00:06:35,840 And same over here. 88 00:06:37,230 --> 00:06:38,040 I do, comma. 89 00:06:41,730 --> 00:06:43,470 And and if I click run. 90 00:06:45,700 --> 00:06:51,790 All right, it's it's getting a little bit better, but now I have an issue where we don't have any 91 00:06:51,880 --> 00:06:52,590 new lines. 92 00:06:52,600 --> 00:06:55,030 Everything is on one line. 93 00:06:55,220 --> 00:06:55,660 Hmm. 94 00:06:56,230 --> 00:06:56,940 That's not good. 95 00:06:56,950 --> 00:06:58,210 How can we solve this? 96 00:06:58,930 --> 00:07:08,740 Well, ideally, at the end of this first loop where we're just going the image or the line in the image, 97 00:07:09,370 --> 00:07:13,330 at the end of this, we create a new line right here. 98 00:07:13,810 --> 00:07:14,220 Right. 99 00:07:14,500 --> 00:07:19,570 So, again, looking at the indentation, I don't want a new line on every pixel. 100 00:07:20,910 --> 00:07:27,660 Which we had the first time, but I also want to add a line between the lists of Rose. 101 00:07:29,050 --> 00:07:38,380 So maybe a better name for this will be a row and picture and in here I'm going to add the end of this 102 00:07:38,380 --> 00:07:42,760 for loop, so after we're done looping through the entire row. 103 00:07:43,980 --> 00:07:45,930 At the bottom here, I'm going to print. 104 00:07:47,220 --> 00:07:51,090 An empty line, but remember, the default is going to be a new line. 105 00:07:52,370 --> 00:07:57,230 So, again, an empty string, it's going to default to a new line and we're still going to have this 106 00:07:57,230 --> 00:07:59,270 code if I run this. 107 00:08:01,740 --> 00:08:07,590 Oh, I get an error because image is not defined because I've just changed this to a row, so let's 108 00:08:07,590 --> 00:08:09,750 do a row here. 109 00:08:10,200 --> 00:08:10,920 Click, run. 110 00:08:13,280 --> 00:08:18,530 And look at that, we have our beautiful Christmas tree, if you don't think this is beautiful, this 111 00:08:18,530 --> 00:08:19,490 is the best I could. 112 00:08:19,760 --> 00:08:21,830 But this is a Christmas tree. 113 00:08:23,060 --> 00:08:28,700 And we finally have a display, we've used Loop's, we've used conditional logic and we used a little 114 00:08:28,700 --> 00:08:33,500 Googling to figure out, hey, we we need this option now. 115 00:08:33,710 --> 00:08:37,700 Our code works, but I want to do something better here. 116 00:08:38,030 --> 00:08:44,780 And in the next video, I want to clean up this code a little bit and cover a very important topic when 117 00:08:44,780 --> 00:08:45,860 it comes to programming. 118 00:08:46,650 --> 00:08:48,090 I'll see in that one, bye bye.