WEBVTT 1 00:00:02.240 --> 00:00:04.430 Okay, so it's now time for a challenge. 2 00:00:04.430 --> 00:00:07.410 From this point forward in the course, anytime we learn something new, 3 00:00:07.410 --> 00:00:09.440 I'm going to issue a challenge. 4 00:00:09.440 --> 00:00:12.520 I'm going to actually type it on the screen shortly, and the idea is for 5 00:00:12.520 --> 00:00:14.095 you to actually go a way. 6 00:00:14.095 --> 00:00:17.025 An attempt to solve this challenge, and actually write some code. 7 00:00:17.025 --> 00:00:18.845 And so, you pause the video while that happens. 8 00:00:18.845 --> 00:00:19.635 And then you write the code. 9 00:00:19.635 --> 00:00:22.225 And then, you'll come back, and actually check the results. 10 00:00:22.225 --> 00:00:22.775 So, what I'll do is, 11 00:00:22.775 --> 00:00:25.767 I'll actually show you my interpretation of the challenge, and the solution. 12 00:00:25.767 --> 00:00:26.792 [INAUDIBLE] To the challenge. 13 00:00:26.792 --> 00:00:29.672 And then, you'll actually look at that, and compare your challenge to it, and 14 00:00:29.672 --> 00:00:32.902 hopefully, you'll learn a lot more about what you've actually just learned. 15 00:00:32.902 --> 00:00:35.072 So, let's go, and get started. 16 00:00:35.072 --> 00:00:38.629 And I'm gonna type in our first challenge, which of course is for the if statement. 17 00:00:52.451 --> 00:00:55.750 Okay, so here is your first challenge in the course. 18 00:00:55.750 --> 00:00:58.590 So, the idea is to write a small program to ask for 19 00:00:58.590 --> 00:01:03.190 a name from the keyboard for the user to type in a name and also an age. 20 00:01:03.190 --> 00:01:05.670 When both values have been entered from a keyboard 21 00:01:05.670 --> 00:01:09.178 check if a person it the right age to go on an 18-30 holiday. 22 00:01:09.178 --> 00:01:14.220 And an 18-30 holiday, what that means is they must be over the age of 18 and 23 00:01:14.220 --> 00:01:18.690 under the age of 31, and if they are, so if they are 18 or 24 00:01:18.690 --> 00:01:21.460 over and under 31, welcome to the holiday. 25 00:01:21.460 --> 00:01:24.050 Otherwise, print a polite message refusing them entry. 26 00:01:24.050 --> 00:01:24.740 And that was a typo there. 27 00:01:24.740 --> 00:01:28.245 Should be otherwise print a polite message refusing them entry. 28 00:01:28.245 --> 00:01:31.430 Alright, so I'll ask you now to pause the video, and actually go away, and 29 00:01:31.430 --> 00:01:33.800 try and come up with the solution to this. 30 00:01:33.800 --> 00:01:37.900 And when you're ready, start the video again, and I'll actually show you how 31 00:01:37.900 --> 00:01:41.140 my solution works, and you can check that against your answer. 32 00:01:41.140 --> 00:01:42.143 So, pause the video now. 33 00:01:46.469 --> 00:01:47.020 Okay. 34 00:01:47.020 --> 00:01:47.550 How did you get on? 35 00:01:47.550 --> 00:01:48.350 Did you figure it out? 36 00:01:48.350 --> 00:01:50.490 Did you have a good attempt at the challenge. 37 00:01:50.490 --> 00:01:52.430 And hopefully, you've figured out a solution to it. 38 00:01:52.430 --> 00:01:55.860 So, let's now, go ahead and actually come up with a solution. 39 00:01:55.860 --> 00:01:57.960 Now, bearing in mind with all challenges, 40 00:01:57.960 --> 00:02:02.150 there's quite often multiple ways to actually achieve things. 41 00:02:02.150 --> 00:02:05.780 And the thing to keep in mind with this is that just because you haven't typed 42 00:02:05.780 --> 00:02:06.900 a challenge, or 43 00:02:06.900 --> 00:02:11.330 solution that's not identical to mine doesn't mean that you got it wrong. 44 00:02:11.330 --> 00:02:15.020 The end result is whether your program has achieved the goals set up in 45 00:02:15.020 --> 00:02:15.810 the challenge. 46 00:02:15.810 --> 00:02:19.890 If it has achieved those goals, then you know, that you've got a good solution. 47 00:02:19.890 --> 00:02:20.600 So, keep that in mind. 48 00:02:20.600 --> 00:02:21.600 Let's get started. 49 00:02:21.600 --> 00:02:22.940 So, first step. 50 00:02:22.940 --> 00:02:24.860 Write a small program to ask for a name and an age. 51 00:02:24.860 --> 00:02:27.400 So we obviously, need to ask for a name and the age. 52 00:02:27.400 --> 00:02:30.820 So, I can type name equals input. 53 00:02:34.560 --> 00:02:36.060 Please enter, your name. 54 00:02:36.060 --> 00:02:41.400 And then, put age equals 55 00:02:41.400 --> 00:02:46.390 int, input, how old are you? 56 00:02:46.390 --> 00:02:52.670 And we'll put a placement field in there, and .format will actually use name. 57 00:02:52.670 --> 00:02:53.340 That was optional, 58 00:02:53.340 --> 00:02:57.030 you didn't have to actually print the name out but that won't be bad if we do that. 59 00:02:57.030 --> 00:03:00.440 Okay, so the next thing we need to do, is now we've got the name and the age, 60 00:03:00.440 --> 00:03:04.940 it's time to see whether the appropriate age to go through to this 18-30 holiday, 61 00:03:04.940 --> 00:03:08.320 and that's obviously to be over 18 and under 31. 62 00:03:08.320 --> 00:03:11.210 I think I said before that it was 18 or older. 63 00:03:11.210 --> 00:03:14.550 But, I've actually typed it as over 18 and under 31. 64 00:03:14.550 --> 00:03:19.570 So, it's up to you if you want to actually put greater than or equal to 18. 65 00:03:19.570 --> 00:03:21.820 Obviously, the correct solution will be either. 66 00:03:21.820 --> 00:03:22.430 Okay. 67 00:03:22.430 --> 00:03:23.260 So, let's just try it. 68 00:03:23.260 --> 00:03:26.530 So, what I'm going to do, I'm going to actually assume that it's an 18-30 69 00:03:26.530 --> 00:03:30.860 holiday, so as long as they're within that range, 18 to 30, they're good to go. 70 00:03:30.860 --> 00:03:36.408 So, one option would be to put if 18 is less than equal to age, 71 00:03:36.408 --> 00:03:38.623 which is less than 31. 72 00:03:39.993 --> 00:03:40.493 Print. 73 00:03:42.383 --> 00:03:46.835 Welcome to club 18-30 holidays. 74 00:03:48.315 --> 00:03:51.075 You replace with field (0).format name. 75 00:03:53.850 --> 00:03:59.360 Else, print I'm sorry, 76 00:03:59.360 --> 00:04:05.560 our holidays are only for seriously cool people. 77 00:04:06.610 --> 00:04:08.630 And so, we've actually fulfilled the criteria. 78 00:04:08.630 --> 00:04:12.150 If they are, we welcome them to the holiday, if they're in that date range. 79 00:04:12.150 --> 00:04:14.380 Otherwise, we put a polite message refusing them entry. 80 00:04:15.900 --> 00:04:16.950 We'll run that challenge. 81 00:04:16.950 --> 00:04:17.960 Now, we'll enter our name. 82 00:04:17.960 --> 00:04:18.710 I'll put Tim. 83 00:04:18.710 --> 00:04:20.610 How old are you Tim? 84 00:04:20.610 --> 00:04:22.140 And notice I made a mistake there. 85 00:04:22.140 --> 00:04:23.840 I should've actually put a space there. 86 00:04:23.840 --> 00:04:26.470 Probably better to put a question mark because it actually is a question. 87 00:04:26.470 --> 00:04:27.550 And then, that space as well. 88 00:04:27.550 --> 00:04:28.630 So, we'll try running that again. 89 00:04:31.370 --> 00:04:32.640 Tim. 90 00:04:32.640 --> 00:04:33.370 How old are you Tim? 91 00:04:33.370 --> 00:04:36.025 21. Welcome to club 1830 Holidays Tim. 92 00:04:36.025 --> 00:04:38.260 Alright, so that's so far so good. 93 00:04:38.260 --> 00:04:39.640 So, let's actually try another scenario. 94 00:04:39.640 --> 00:04:40.920 Tim. 18. 95 00:04:40.920 --> 00:04:43.950 Welcome to club 1830 Holidays Tim. 96 00:04:43.950 --> 00:04:45.520 Yes, we still fulfilled it. 97 00:04:45.520 --> 00:04:48.780 But now if we type Tim again, or type Thomas. 98 00:04:48.780 --> 00:04:50.880 Thomas [INAUDIBLE] something different. 99 00:04:50.880 --> 00:04:51.640 17. 100 00:04:51.640 --> 00:04:54.840 I'm sorry our holidays are only for seriously cool people. 101 00:04:54.840 --> 00:04:56.320 So obviously, this 17 is working, 102 00:04:56.320 --> 00:05:00.500 and if we actually do another test here we can put Brian 31. 103 00:05:00.500 --> 00:05:04.020 I'm sorry our holidays are only for seriously cool people. 104 00:05:04.020 --> 00:05:05.420 So, that's working as well. 105 00:05:05.420 --> 00:05:10.050 So, this was one way to actually test, and obviously, that's just one way, but 106 00:05:10.050 --> 00:05:12.620 we could also have done, if I comment that out, 107 00:05:12.620 --> 00:05:17.900 we could quite easily also have put if age is greater than or 108 00:05:17.900 --> 00:05:22.720 equal to 18 and age is less than 31. 109 00:05:22.720 --> 00:05:25.010 We could have done that, and 110 00:05:25.010 --> 00:05:29.530 if we run that it'll actually give us the same result. 111 00:05:29.530 --> 00:05:34.370 So, if I put 17 in there, excluded as we should be. 112 00:05:34.370 --> 00:05:35.400 Tim. 18. 113 00:05:35.400 --> 00:05:37.300 Welcome to Club 1830 Holidays Tim. 114 00:05:37.300 --> 00:05:38.770 That's correct. 115 00:05:38.770 --> 00:05:45.175 And likewise try 31, we should be excluded cuz the range was 18 to 30. 116 00:05:45.175 --> 00:05:47.355 And the last one, Tim, say 25 or 117 00:05:47.355 --> 00:05:50.955 actually put 5 [INAUDIBLE], actually was going to say I put 5 there, but 118 00:05:50.955 --> 00:05:53.475 I actually typed ahead, and did actually put 25, so that's correct. 119 00:05:53.475 --> 00:05:55.755 So, there you go, that's the first challenge, and again so 120 00:05:55.755 --> 00:05:58.630 depending on your answer if you did it a different way there, 121 00:05:58.630 --> 00:06:02.320 you could have used even the or, as we talked about in this lesson, or 122 00:06:02.320 --> 00:06:07.390 in the previous parts of this if statement lessons, the two previous videos. 123 00:06:07.390 --> 00:06:08.310 That would've been correct. 124 00:06:08.310 --> 00:06:11.330 The main thing is that you're able to actually check that they're actually 125 00:06:11.330 --> 00:06:11.920 within that range. 126 00:06:11.920 --> 00:06:14.270 And if they were in your program, congratulations. 127 00:06:14.270 --> 00:06:15.020 You did well. 128 00:06:15.020 --> 00:06:17.160 Okay. That's it for the if statement, so 129 00:06:17.160 --> 00:06:18.760 we've gone through and learned how to do that. 130 00:06:18.760 --> 00:06:20.620 We've also gone through a challenge. 131 00:06:20.620 --> 00:06:23.380 In the next video, we're gonna start looking at for-loops which is 132 00:06:23.380 --> 00:06:27.610 a way to actually repeat certain code, or code blocks a certain amount of times, so 133 00:06:27.610 --> 00:06:28.880 I'll see you in that next video.