WEBVTT 00:05.540 --> 00:06.290 Welcome back. 00:06.650 --> 00:12.310 Previously, you learned how to generate random numbers by seeding the round package in his lecture, 00:12.320 --> 00:14.400 I'm going to create the actual lucky number. 00:15.290 --> 00:16.180 So let's get started. 00:19.700 --> 00:26.270 OK, let's start by seeding the round package first by using the ever changing methods like this. 00:29.910 --> 00:32.340 Donnelly's declare the guest number like this. 00:34.010 --> 00:36.740 Then I'm going to have four or five times like this. 00:39.080 --> 00:44.270 And instead of the follow up, I'm going to generate a random number between Zero and Geass plus one. 00:46.180 --> 00:50.050 Then I'm going to check whether the random number is equal to the guest number. 00:51.220 --> 00:58.330 If An equals to guess, OK, if so, then I'm going to print a message like this printed on. 00:59.410 --> 01:00.100 You win. 01:01.350 --> 01:06.720 And right after the loop, if the user couldn't be here, I'm going to print the lost message like this. 01:12.710 --> 01:14.030 You lost again. 01:17.110 --> 01:18.250 All right, let's try right the. 01:22.400 --> 01:27.590 Here, even though the user wins, the loop doesn't end, and when it's done, it brings the loss message 01:27.590 --> 01:28.320 here as well. 01:28.730 --> 01:29.630 What's going on? 01:29.930 --> 01:31.820 There is probably a bug, right? 01:32.150 --> 01:36.140 So how can you solve this post video and think about it? 01:44.250 --> 01:52.110 OK, to solve this one, the user wins the program short, and to do that, I can use the return statement 01:52.110 --> 01:54.540 to return from the main function like this. 01:55.650 --> 02:01.290 This way and the user wins, the program will be terminated and the loss message won't get displayed 02:01.410 --> 02:01.770 at. 02:03.760 --> 02:04.660 So let's run it again. 02:07.590 --> 02:11.070 As you can see, Prince, the wind and lost messages correctly. 02:12.200 --> 02:14.510 Now, let's refactor this program a little bit. 02:15.560 --> 02:22.460 This convert, this magic number five here into a constant I'm going to type Maxitrans here now I'm 02:22.460 --> 02:24.050 going to declare a new Konstanty. 02:24.930 --> 02:28.800 By the way, Max Terms determines the difficulty of the game, actually. 02:30.260 --> 02:36.540 So when it gets bigger, the game will be easier because there will be more chances for finding the 02:36.560 --> 02:41.680 guest number right or when it gets smaller, game will be harder. 02:43.420 --> 02:47.810 OK, now, instead of typing the number manually, let's get it from the command line. 02:48.750 --> 02:52.330 First, I'm going to save the arguments into the ARC's variable like this. 02:53.350 --> 02:55.720 Then I'm going to get the guest number from the ARC's. 02:57.420 --> 03:03.500 OK, now I need to convert it into an integer number, right, to do that, I'm going to call the I 03:03.570 --> 03:03.990 function. 03:07.290 --> 03:09.120 OK, now this check for their. 03:10.230 --> 03:16.170 If Aitor isn't new now, let's display an error message here. 03:18.610 --> 03:25.570 OK, here, I also need to return so that when there is an error, the rest of the court wants run. 03:26.180 --> 03:28.330 OK, all right, that's it. 03:28.480 --> 03:28.960 That's right. 03:28.960 --> 03:31.150 Now I'm going to guess five. 03:34.010 --> 03:35.750 Good, eventually it works. 03:37.070 --> 03:41.010 Now, let's try to run it with a negative number minus five. 03:41.660 --> 03:46.890 Wow, that's crashed because the intown function doesn't accept negative numbers. 03:47.090 --> 03:48.110 So what we can do. 03:49.490 --> 03:54.700 So when the user picks a negative number, let's warn the user and quit from the program, right. 03:55.130 --> 03:55.910 That's the solution. 03:56.690 --> 03:59.240 Now I'm going to check whether the guess is negative like this. 04:00.460 --> 04:02.410 Yes, is less than zero. 04:03.370 --> 04:09.760 OK, and if so, I'm going to print a message like this, please pick a positive number now I need to 04:09.760 --> 04:12.290 terminate the program, so I'm going to type return. 04:12.940 --> 04:13.630 OK, the. 04:14.660 --> 04:15.400 Let's try it again. 04:17.730 --> 04:19.700 As you can see, it works perfectly now. 04:20.880 --> 04:24.480 This time, let's try running it without any arguments whatsoever. 04:25.590 --> 04:27.180 I do think that will happen now. 04:28.360 --> 04:29.170 Kate, the sea. 04:30.340 --> 04:34.380 It's crash a second since I didn't check the number of arguments passed to the program. 04:35.050 --> 04:35.310 Right. 04:35.740 --> 04:36.550 Let's do that now. 04:38.120 --> 04:40.580 You know, I'm going to check whether there is an argument or not. 04:43.160 --> 04:46.010 If not, then I'm going to print the usage message like this. 04:47.310 --> 04:47.770 A No. 04:49.080 --> 04:50.900 And I'm going to terminate from the program. 04:53.010 --> 04:54.180 OK, let's try it again. 04:56.080 --> 04:56.420 Good. 04:56.500 --> 04:57.240 It works now. 04:58.220 --> 05:01.610 I think that it be better to display a proper usage message. 05:03.310 --> 05:07.390 First, I'm going to create a usage constant by using a real string literal like this. 05:10.410 --> 05:15.350 Let's first print the name of the game and let's talk a little bit about the goal of the game. 05:16.870 --> 05:18.690 Thumbprint, the teaser for the user. 05:19.920 --> 05:21.580 All right, looks good here. 05:21.600 --> 05:25.320 I've used the verb, I'll use it to print how many times the user will have. 05:26.280 --> 05:29.650 Right, to print the usage message, I'm going to replace this shrink here. 05:30.950 --> 05:37.280 With the usage constant like this now, the printed function will replace the verb inside the usage 05:37.280 --> 05:40.270 constant with the value of the Maxitrans constant. 05:40.490 --> 05:44.110 OK, OK, now let's try it and see how it works. 05:53.730 --> 05:54.990 I think this looks better. 05:55.590 --> 05:57.740 All right, that's all for this project. 05:59.680 --> 06:05.280 Now it's your turn without solving problems with go, please don't expect that you'll be a gofer. 06:06.010 --> 06:11.670 So I prepared a lot of exercise for you is important that you try doing time on your own. 06:13.720 --> 06:21.520 First turn winner, first exercise, first term Vener, so if the first random number by the computer 06:21.520 --> 06:25.570 matches the player's guess can print a special bonus message. 06:26.320 --> 06:32.700 This will only happen if the computer picks the user's case number at the first time. 06:32.710 --> 06:33.040 OK. 06:34.750 --> 06:42.700 Second exercise is random messages, so at the end of the game, print random win and loss messages. 06:43.960 --> 06:51.130 So currently, the program only displays one winning message, but I want you to display around them 06:51.130 --> 06:53.810 winning messages each time the user wins. 06:53.940 --> 06:54.290 OK. 06:55.310 --> 07:02.210 Cool to do that, you can use a switch statement and the income function in its condition, no more 07:02.210 --> 07:03.710 clues, sorry. 07:04.960 --> 07:10.280 Currently, the player gets a small number, right, instead of one, let the player guess two numbers. 07:10.900 --> 07:15.220 So when either of them are picked by the computer that print the winning message. 07:18.570 --> 07:23.760 For the details and the rest of the exercises, please check out the loop exercises further in the course 07:23.800 --> 07:24.440 repository. 07:25.150 --> 07:26.430 OK, that's all for now. 07:27.860 --> 07:29.160 All right, thank you for watching. 07:29.270 --> 07:30.200 See in the next picture.