All right. Now,
the first turtle challenge I've got for you is pretty easy.
It's kind of like doing your stretches before we get started with the proper
workout. So in this challenge, you're going to be using turtle to draw a square.
It's going to be a simple 100 by 100 square,
and it doesn't matter where it is on the screen.
As long as you can get it to draw this, then consider yourself successful.
Pause the video, have a read through the documentation,
have a think about the challenge and go ahead and complete it.
All right.
So I'm going to comment out the previous lines of code other than the line where
we created our timmy_
the_turtle. Now to draw a square is pretty simple.
All we have to do is to get it to go forwards by a hundred paces,
and then we turn left or turn right by 90 degrees.
And then we get it to repeat this process one time for each of the sides.
And when we run the code,
now you can see it draws a simple square. Now,
of course, because we're programmers and we're lazy
and we don't like looking at repeated code, a much simpler way of doing this is
to simply create a for loop.
And we're going to use the range operator to say that this loop should run four
times and then let's indent these two lines of code.
And now it will do exactly the same as before
but this time we've only had to write three lines of code instead of a million.
This is probably the best solution,
but I will also take this solution because after all,
we're just doing the warmup right? Now, while doing that exercise
you might have realized that it's actually really painful to keep calling our
object timmy_the_turtle with such a long name.
But now that we've written it in so many lines
especially if you created this version of the code,
it's actually quite painful to go through each of them and change its name.
Remember in PyCharm
we have a really simple way of changing the name of a variable or a function,
basically anything that we've named ourselves. All we have to do is right-
click on the name, refactor and rename,
and we can change it to something really simple like how about Tim. Now
we've drastically made our code look a lot simpler just by doing that one thing.
I'll try to remind you of some of these shortcuts as we go along,
but once you're ready, head over to the next challenge.