Instructor: All right, your head must be spinning
because of all these looping.
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 gonna be my last video for the day,
not for the course,
but we're gonna do a little fun exercise.
Now, I call all exercises fun.
Obviously I'm biased, but this one's especially fun.
What are we going to do?
Well, we're going to simulate what a computer does
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 gonna 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 ripple 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 a one, I wanna 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 want it 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 computer's 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.
Pause the video, give it a go,
otherwise, I'm gonna 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 wanna make sure that we have a plan in mind.
So I'm going to comment first,
and I'm going to say,
while we definitely wanna iterate over picture, right?
So we're gonna do some sort of iteration here.
So that's number one.
And then in here, I wanna say that if it's a zero,
then I wanna print an empty space.
And if it's a one, I wanna print a star,
right?
So that's the plan.
Okay, 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 a 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 end 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 end option.
Now, I know I left it really vague.
I want you to practice Googling this.
And figuring out from your mistake,
you're gonna 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 wanna 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 for 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 pixel equals one,
then I'm going to print 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, hmm, that's not really what 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 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, end.
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.
If I do comma,
end, and if I click run.
All right, 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 wanna add a line between the lists of rows.
So maybe a better name for this will be a row in picture.
And in here, I'm going to add at the end of this for loop,
so after we're done looping through the entire row,
the bottom here, I'm going to print an empty line.
But remember, the default is gonna be a new line.
So again, an empty string,
it's going to default to a new line.
And we're still gonna have this code.
If I run this, I get an error because image is not defined
because I've just changed this to a row.
So let's do 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 it displaying.
We've used loops, we've used conditional logic,
and we used a little Googling to figure out,
hey, we need this option.
Now our code works, but I wanna do something better here.
And in the next video, I wanna clean up this code
a little bit and cover a very important topic when it comes
to programming.
I'll see you in that one.
Bye bye.