WEBVTT 00:00.530 --> 00:06.590 Welcome in this section, we'll start with a challenge, so you'll use everything you have learned so 00:06.590 --> 00:11.570 far and you cannot create a digital clock that runs entirely on the comment line. 00:12.550 --> 00:18.490 First of all, let me show you what the final program is going to look like, I'm just going to run 00:18.490 --> 00:19.030 the program. 00:20.420 --> 00:27.290 As you can see, the clock is being updated every second and it has this cool effect, I mean, the 00:27.300 --> 00:29.750 separators are blinking every two seconds. 00:30.650 --> 00:32.650 Let me tell you how this works. 00:33.500 --> 00:40.280 So every second the program clears the command line screen and redraws the clock again and again in 00:40.280 --> 00:41.460 the same position. 00:41.520 --> 00:41.840 OK. 00:43.430 --> 00:47.570 This creates the illusion that the clock is being animated. 00:48.620 --> 00:55.520 I can quit from this program only by killing it because it runs in an infinite loop so it never quits. 00:56.450 --> 00:59.900 So I'm going to press control key is to terminate it. 01:00.320 --> 01:04.820 All right, let's talk a little bit about how we can create this program by yourself. 01:07.010 --> 01:13.700 First of all, you would need to create an array for each digit so there will be 10 arrays for each 01:13.700 --> 01:14.100 digit. 01:14.960 --> 01:18.530 So how can you create these digits using arrays? 01:19.400 --> 01:20.060 Let me show you. 01:22.010 --> 01:29.360 For example, let's take a look at these digits in detail, these digits is actually an array with five 01:29.360 --> 01:30.560 string elements. 01:31.560 --> 01:39.200 These yellow lines represent the areas elements I know there are six lines, but think of them as areas. 01:39.390 --> 01:41.820 So there are five elements in this area. 01:42.730 --> 01:48.790 So the first element contains the first line and the second element contains the second line, and it 01:48.790 --> 01:54.220 goes like this, you need to put each digit into its own array variable. 01:54.430 --> 01:55.060 Let me show you. 01:56.780 --> 02:03.620 Like this, as you can see, I created a new string array with five elements, then I put each line 02:03.620 --> 02:09.710 of the digit in an array variable named zero, you would need to create variables like this for each 02:09.710 --> 02:10.130 digit. 02:10.400 --> 02:10.760 OK. 02:12.320 --> 02:14.390 OK, let's get back to the digits. 02:15.610 --> 02:21.580 After creating the digits from zero to nine, then you would need to create a multidimensional array 02:21.580 --> 02:25.360 such as this one in this area, you're going to store the digits. 02:26.210 --> 02:29.910 These red lines represent the elements of these digits array. 02:29.950 --> 02:32.100 As you can see, there are 10 elements. 02:32.980 --> 02:36.910 These yellow lines represent the elements of the inner arrays. 02:37.630 --> 02:42.880 So each inner element is actually a digital era that you saw just before. 02:42.970 --> 02:48.520 OK, so you can use these digits and then you can create the clock for the current time. 02:48.640 --> 02:54.310 To do that, you would need to create a clock array and then you would need to populate it using these 02:54.310 --> 02:54.830 digits. 02:55.570 --> 02:58.530 I'm going to show you what the clock array looks like next. 02:58.780 --> 03:02.220 So it contains eight placeholders for each column. 03:02.230 --> 03:02.580 Right. 03:02.980 --> 03:05.640 Let me show you what this looks like as an array. 03:06.220 --> 03:10.840 So the clock is actually a multidimensional array with eight elements. 03:11.440 --> 03:17.380 It contains eight placeholders, and each placeholder is a string array with five string elements. 03:18.160 --> 03:20.890 Red lines represent the placeholder arrays. 03:22.270 --> 03:26.080 And the yellow lines represent the elements of each placeholder array. 03:27.800 --> 03:34.850 There are also two separate air currents, a separate there is also an array, just like a digital, 03:35.330 --> 03:39.590 a separator or a digit, I call both of them placeholders. 03:39.980 --> 03:44.480 There are no difference between them is because they are the same type of arrays. 03:46.040 --> 03:49.340 Depending on the current time, you would need to update the clock. 03:50.240 --> 03:56.210 As I said, you can get the digits from the digits array, then you can copy the digits into this clock. 03:57.320 --> 04:02.460 After you copied the placeholders, you can use this clock array to print the clock. 04:02.990 --> 04:04.930 So how can you get the current time? 04:06.440 --> 04:12.800 As you know, you can get the current time using the time that now method and through that you can get 04:12.800 --> 04:17.510 the current hour, minute and second by using these methods that you can see here. 04:19.140 --> 04:25.140 You would also need to wrap your coat in an infinite loop, this way you'll be able to update the clock 04:25.140 --> 04:27.270 until the user quits the program. 04:28.560 --> 04:34.530 Of course, running your court in an infinite loop will consume unnecessary CPU resources, you would 04:34.530 --> 04:39.690 need to slow it down so you can use the time that sleep function to sleep for one second. 04:39.690 --> 04:46.320 At the end of every loop, you can find the link to this function in the resources, by the way, it 04:46.320 --> 04:51.510 just takes the time that duration value and stops the world for the given time duration. 04:51.540 --> 04:51.870 OK. 04:52.790 --> 04:55.910 OK, now let's talk about how to clear the screen. 04:56.860 --> 05:03.010 Just before entering the infinite loop, you would need to clear the screen once after that, you need 05:03.010 --> 05:06.480 to move the cursor to the top left position of the screen. 05:07.210 --> 05:11.920 By doing so, you'll be able to draw the clock on a clean screen every second. 05:12.550 --> 05:17.200 Don't worry, I'll I've explained everything in the challenge documentation or in the card. 05:17.830 --> 05:20.980 You can find it in the resources of this lecture as a link. 05:22.650 --> 05:29.570 OK, let's talk a little bit about the worry of the general algorithm for this challenge, first, create 05:29.580 --> 05:31.470 the digits from zero to nine. 05:31.890 --> 05:33.390 They all will be erased. 05:33.990 --> 05:40.140 That clear the screen once and for all before the infinite loop and after that create an infinite loop. 05:40.470 --> 05:46.740 In this loop, you'll draw the clock continuously to the screen inside the loop, move the cursor to 05:46.740 --> 05:48.830 the top left position of the screen. 05:49.050 --> 05:53.880 Doing so will allow you to recreate the clock on a clean screen at the same position. 05:53.880 --> 05:54.360 Always. 05:55.410 --> 06:01.770 And after that update, the clocker, by copying the necessary digits and the separators into it, and 06:01.770 --> 06:07.000 after that, you need to draw the clock using the clock line by line to the screen. 06:07.740 --> 06:11.730 And lastly, wait one second before drawing the next clock. 06:12.030 --> 06:15.920 This loop will continue until you terminate from the program. 06:17.750 --> 06:23.870 As I said, I explained everything about this challenge with step by step instructions in the course 06:23.870 --> 06:27.980 of the Post story, so please check out the link in the resources of this lecture. 06:28.200 --> 06:31.310 It will take you to the step by step challenge explanation. 06:31.520 --> 06:31.940 All right. 06:32.090 --> 06:32.900 That's all for now. 06:33.020 --> 06:35.180 Trust yourself because I trust you. 06:35.210 --> 06:37.100 You can solve this challenge. 06:37.110 --> 06:38.720 You have all the knowledge. 06:38.740 --> 06:40.940 See the solution, lectures them by.