All right.
Your head must be spinning because of all these looping, that's that's a really bad joke.
But I thought it was funny because I've been recording for hours now and I think I'm going a little
kooky.
So this is going to be my last video for the day now forth, of course, but we're going to do a little
fun exercise now.
I call all exercise is fun.
Obviously I'm biased, but this one, this one's especially fun.
Why are we going to do.
Well, we're going to simulate what a computer does when when we have something like a graphical user
interface that is a computer is able to display, let's say, even an image over here.
Right.
I can see the robot over here.
I can see the mouse.
This is a graphical user interface.
I see pictures.
I see images on my screen, these pixels on my screen, and I can control them.
Well, we're going to create a basic version of this to show you how a computer would work just from
the stuff that we've learned up until now, using loops and using conditional logic.
So what are we going to do?
Well, this is the exercise and you can check out the Reppel here or you can recreate this or again
in this video, you should have resources attached that you can play with it yourself.
And what I want you to do is I want you to loop through this list of lists.
And every time you encounter a zero, I want you to display on the screen over here an empty space.
Because a zero in a computer denotes nothing, right, we want a blank on the screen.
However, when I see one, I want to simulate a pixel right that tiny, tiny dot on our computers that
can be full of colors.
It could be green.
It can be blue.
It can be orange.
But for our case, I wanted to be a star.
And using that, I want you to create a program that takes this picture that let's say is in our database
or in our computers hard drive and displays it on the screen using space or multiply.
And all I want you to do is when I click run, I want you to display that image right here.
All right.
This is a little tough one, and I'm kind of letting you figure out on your own.
But trust me, you've learned all the tools necessary to do this.
Pausa.
Video.
Give it a go.
Otherwise, I'm going to show you how it's done.
So the very first thing I like to do is to think about what I'm about to do.
I want to make sure that we have a plan in mind.
So I'm going to comment first and I'm going to say, well, we definitely want to iterate over picture.
Right, so we're going to do some sort of iteration here, so that's number one.
And then in here, I want to say that if it's a zero, then I want to print an empty space.
And if it's a one.
All right, so that's the plan.
OK, so this shouldn't be too hard, actually, before you get started, in order for this to work,
you need to Google a special parameter or special option that you can give the print function.
And as a matter of fact, the print function that you need to add or the option that you need to add
is this and.
Option, and if we scroll down, it doesn't display it that well, but you can see here string appended
after the last value.
So the default when we print something is a new line.
But ideally, we might not want a new line.
So when that happens, you might have to use this and.
Option now I know I left it really vague, I want to I want you to practice Googling this and and figuring
out from your mistake you're going to have a bug when you create this code, when you try to display
this information, but try to solve it using the tools that you have of problem solving.
All right, enough talk, let's get to it.
So the first thing I want to do is iterate over the picture, I'm going to say for image in picture
because, well, this is one picture right here.
So this is the picture, but it's inside of a list because we can have multiple pictures.
And then I'm going to loop once again over this individual list.
So once again, I need to do a for loop.
And this time I'm going to say four pixel because each one of this is a pixel.
In the image, so this is a nested for loop.
Now, I'm going to add a conditional and say if.
Equals one.
Then I'm going to.
A star.
Otherwise.
I'm going to print.
An empty string.
Well, maybe not empty, right, because we do want a space, a blank space in the image.
All right.
So let's see if this works.
If I click, run.
That's not really why I wanted.
I want a clear image here, but I'm just getting things one in line and remember, this was the little
trick where a print, every time it prints, it creates a new line.
The default, again, if we close this, you'll see.
Is that end equals to this escape sequence of new line, so we can change that by simply saying.
Star, comma, and and then I'm going to say for the end, I don't want a new line, I just want.
Well, a string but an empty string.
And same over here.
I do, comma.
And and if I click run.
All right, it's it's getting a little bit better, but now I have an issue where we don't have any
new lines.
Everything is on one line.
Hmm.
That's not good.
How can we solve this?
Well, ideally, at the end of this first loop where we're just going the image or the line in the image,
at the end of this, we create a new line right here.
Right.
So, again, looking at the indentation, I don't want a new line on every pixel.
Which we had the first time, but I also want to add a line between the lists of Rose.
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
for loop, so after we're done looping through the entire row.
At the bottom here, I'm going to print.
An empty line, but remember, the default is going to be a new line.
So, again, an empty string, it's going to default to a new line and we're still going to have this
code if I run this.
Oh, I get an error because image is not defined because I've just changed this to a row, so let's
do a row here.
Click, run.
And look at that, we have our beautiful Christmas tree, if you don't think this is beautiful, this
is the best I could.
But this is a Christmas tree.
And we finally have a display, we've used Loop's, we've used conditional logic and we used a little
Googling to figure out, hey, we we need this option now.
Our code works, but I want to do something better here.
And in the next video, I want to clean up this code a little bit and cover a very important topic when
it comes to programming.
I'll see in that one, bye bye.