WEBVTT

0
00:00.420 --> 00:01.050
All right. Now,

1
00:01.050 --> 00:05.460
the first turtle challenge I've got for you is pretty easy.

2
00:05.490 --> 00:09.060
It's kind of like doing your stretches before we get started with the proper

3
00:09.060 --> 00:14.040
workout. So in this challenge, you're going to be using turtle to draw a square.

4
00:14.400 --> 00:17.610
It's going to be a simple 100 by 100 square,

5
00:18.060 --> 00:19.980
and it doesn't matter where it is on the screen.

6
00:20.250 --> 00:24.000
As long as you can get it to draw this, then consider yourself successful.

7
00:24.600 --> 00:27.300
Pause the video, have a read through the documentation,

8
00:27.330 --> 00:30.510
have a think about the challenge and go ahead and complete it.

9
00:34.590 --> 00:34.920
All right.

10
00:34.920 --> 00:38.370
So I'm going to comment out the previous lines of code other than the line where

11
00:38.370 --> 00:39.960
we created our timmy_

12
00:39.960 --> 00:43.890
the_turtle. Now to draw a square is pretty simple.

13
00:43.920 --> 00:48.240
All we have to do is to get it to go forwards by a hundred paces,

14
00:48.570 --> 00:52.470
and then we turn left or turn right by 90 degrees.

15
00:52.890 --> 00:57.890
And then we get it to repeat this process one time for each of the sides.

16
00:58.320 --> 00:59.760
And when we run the code,

17
00:59.820 --> 01:04.680
now you can see it draws a simple square. Now,

18
01:04.680 --> 01:07.410
of course, because we're programmers and we're lazy

19
01:07.410 --> 01:11.970
and we don't like looking at repeated code, a much simpler way of doing this is

20
01:11.970 --> 01:13.920
to simply create a for loop.

21
01:14.280 --> 01:19.280
And we're going to use the range operator to say that this loop should run four

22
01:19.830 --> 01:23.040
times and then let's indent these two lines of code.

23
01:23.490 --> 01:26.640
And now it will do exactly the same as before

24
01:26.940 --> 01:31.140
but this time we've only had to write three lines of code instead of a million.

25
01:31.350 --> 01:33.720
This is probably the best solution,

26
01:33.810 --> 01:38.340
but I will also take this solution because after all,

27
01:38.370 --> 01:42.240
we're just doing the warmup right? Now, while doing that exercise

28
01:42.270 --> 01:46.260
you might have realized that it's actually really painful to keep calling our

29
01:46.260 --> 01:49.590
object timmy_the_turtle with such a long name.

30
01:50.100 --> 01:52.710
But now that we've written it in so many lines

31
01:52.770 --> 01:55.020
especially if you created this version of the code,

32
01:55.410 --> 01:58.920
it's actually quite painful to go through each of them and change its name.

33
01:59.400 --> 02:00.840
Remember in PyCharm

34
02:00.840 --> 02:05.370
we have a really simple way of changing the name of a variable or a function,

35
02:05.550 --> 02:09.840
basically anything that we've named ourselves. All we have to do is right-

36
02:09.840 --> 02:12.300
click on the name, refactor and rename,

37
02:12.630 --> 02:17.100
and we can change it to something really simple like how about Tim. Now

38
02:17.100 --> 02:21.600
we've drastically made our code look a lot simpler just by doing that one thing.

39
02:22.500 --> 02:25.440
I'll try to remind you of some of these shortcuts as we go along,

40
02:25.860 --> 02:28.530
but once you're ready, head over to the next challenge.