1
00:00:00,420 --> 00:00:01,050
All right. Now,

2
00:00:01,050 --> 00:00:05,460
the first turtle challenge I've got for you is pretty easy.

3
00:00:05,490 --> 00:00:09,060
It's kind of like doing your stretches before we get started with the proper

4
00:00:09,060 --> 00:00:14,040
workout. So in this challenge, you're going to be using turtle to draw a square.

5
00:00:14,400 --> 00:00:17,610
It's going to be a simple 100 by 100 square,

6
00:00:18,060 --> 00:00:19,980
and it doesn't matter where it is on the screen.

7
00:00:20,250 --> 00:00:24,000
As long as you can get it to draw this, then consider yourself successful.

8
00:00:24,600 --> 00:00:27,300
Pause the video, have a read through the documentation,

9
00:00:27,330 --> 00:00:30,510
have a think about the challenge and go ahead and complete it.

10
00:00:34,590 --> 00:00:34,920
All right.

11
00:00:34,920 --> 00:00:38,370
So I'm going to comment out the previous lines of code other than the line where

12
00:00:38,370 --> 00:00:39,960
we created our timmy_

13
00:00:39,960 --> 00:00:43,890
the_turtle. Now to draw a square is pretty simple.

14
00:00:43,920 --> 00:00:48,240
All we have to do is to get it to go forwards by a hundred paces,

15
00:00:48,570 --> 00:00:52,470
and then we turn left or turn right by 90 degrees.

16
00:00:52,890 --> 00:00:57,890
And then we get it to repeat this process one time for each of the sides.

17
00:00:58,320 --> 00:00:59,760
And when we run the code,

18
00:00:59,820 --> 00:01:04,680
now you can see it draws a simple square. Now,

19
00:01:04,680 --> 00:01:07,410
of course, because we're programmers and we're lazy

20
00:01:07,410 --> 00:01:11,970
and we don't like looking at repeated code, a much simpler way of doing this is

21
00:01:11,970 --> 00:01:13,920
to simply create a for loop.

22
00:01:14,280 --> 00:01:19,280
And we're going to use the range operator to say that this loop should run four

23
00:01:19,830 --> 00:01:23,040
times and then let's indent these two lines of code.

24
00:01:23,490 --> 00:01:26,640
And now it will do exactly the same as before

25
00:01:26,940 --> 00:01:31,140
but this time we've only had to write three lines of code instead of a million.

26
00:01:31,350 --> 00:01:33,720
This is probably the best solution,

27
00:01:33,810 --> 00:01:38,340
but I will also take this solution because after all,

28
00:01:38,370 --> 00:01:42,240
we're just doing the warmup right? Now, while doing that exercise

29
00:01:42,270 --> 00:01:46,260
you might have realized that it's actually really painful to keep calling our

30
00:01:46,260 --> 00:01:49,590
object timmy_the_turtle with such a long name.

31
00:01:50,100 --> 00:01:52,710
But now that we've written it in so many lines

32
00:01:52,770 --> 00:01:55,020
especially if you created this version of the code,

33
00:01:55,410 --> 00:01:58,920
it's actually quite painful to go through each of them and change its name.

34
00:01:59,400 --> 00:02:00,840
Remember in PyCharm

35
00:02:00,840 --> 00:02:05,370
we have a really simple way of changing the name of a variable or a function,

36
00:02:05,550 --> 00:02:09,840
basically anything that we've named ourselves. All we have to do is right-

37
00:02:09,840 --> 00:02:12,300
click on the name, refactor and rename,

38
00:02:12,630 --> 00:02:17,100
and we can change it to something really simple like how about Tim. Now

39
00:02:17,100 --> 00:02:21,600
we've drastically made our code look a lot simpler just by doing that one thing.

40
00:02:22,500 --> 00:02:25,440
I'll try to remind you of some of these shortcuts as we go along,

41
00:02:25,860 --> 00:02:28,530
but once you're ready, head over to the next challenge.

