WEBVTT 1 00:00:01.160 --> 00:00:03.620 so in this section we looked at blocks in 2 00:00:03.620 --> 00:00:05.450 python and seen how the level of so in this section we looked at blocks in 3 00:00:05.450 --> 00:00:07.910 indentation is crucial in determining python and seen how the level of 4 00:00:07.910 --> 00:00:10.580 which block a line of code belongs to indentation is crucial in determining 5 00:00:10.580 --> 00:00:12.740 we then use if and else to test which block a line of code belongs to 6 00:00:12.740 --> 00:00:15.080 conditions and only execute blocks of we then use if and else to test 7 00:00:15.080 --> 00:00:16.670 code if those conditions were either conditions and only execute blocks of 8 00:00:16.670 --> 00:00:18.140 true or false code if those conditions were either 9 00:00:18.140 --> 00:00:20.000 we then went to create more complex true or false 10 00:00:20.000 --> 00:00:22.789 conditions and saw how to use Elif to we then went to create more complex 11 00:00:22.789 --> 00:00:25.820 check several conditions in turn so next conditions and saw how to use Elif to 12 00:00:25.820 --> 00:00:28.699 we moved on to execute blocks of code check several conditions in turn so next 13 00:00:28.699 --> 00:00:31.279 repeatedly using for statements to we moved on to execute blocks of code 14 00:00:31.279 --> 00:00:33.860 iterate through a range of values we repeatedly using for statements to 15 00:00:33.860 --> 00:00:36.079 covered continue and break to interrupt the iterate through a range of values we 16 00:00:36.079 --> 00:00:38.300 normal flow of a for loop and else to covered continue and break to interrupt the 17 00:00:38.300 --> 00:00:40.489 define a block that always execute if normal flow of a for loop and else to 18 00:00:40.489 --> 00:00:43.039 the loop finishes without a break define a block that always execute if 19 00:00:43.039 --> 00:00:44.600 this is a different use of the else the loop finishes without a break 20 00:00:44.600 --> 00:00:46.550 keyword to how it's used in an if this is a different use of the else 21 00:00:46.550 --> 00:00:48.350 statement which is a little unfortunate keyword to how it's used in an if 22 00:00:48.350 --> 00:00:51.410 and can also be confusing but that's the statement which is a little unfortunate 23 00:00:51.410 --> 00:00:53.420 keyword that has been chosen so we have and can also be confusing but that's the 24 00:00:53.420 --> 00:00:55.010 to actually live with that unfortunately keyword that has been chosen so we have 25 00:00:55.010 --> 00:00:58.039 and then finally we digress to look at to actually live with that unfortunately 26 00:00:58.039 --> 00:01:00.050 augmented assignment and why you should and then finally we digress to look at 27 00:01:00.050 --> 00:01:01.640 use it in preference to a normal augmented assignment and why you should 28 00:01:01.640 --> 00:01:03.769 assignment where possible or whenever use it in preference to a normal 29 00:01:03.769 --> 00:01:04.790 possible assignment where possible or whenever 30 00:01:04.790 --> 00:01:06.290 I'm going to finish this section now possible 31 00:01:06.290 --> 00:01:08.270 with the short challenge to give you a I'm going to finish this section now 32 00:01:08.270 --> 00:01:09.920 chance to practice what you've learned with the short challenge to give you a 33 00:01:09.920 --> 00:01:12.080 in the course so far and you have a chance to practice what you've learned 34 00:01:12.080 --> 00:01:13.400 chance to make use of the string in the course so far and you have a 35 00:01:13.400 --> 00:01:15.350 formatting that we covered in previous chance to make use of the string 36 00:01:15.350 --> 00:01:17.600 videos as well as reading an input that formatting that we covered in previous 37 00:01:17.600 --> 00:01:20.210 a user types at the keyboard so i'm videos as well as reading an input that 38 00:01:20.210 --> 00:01:21.980 going to do now is create a new python file a user types at the keyboard so i'm 39 00:01:21.980 --> 00:01:25.310 i'm just going to paste in the going to do now is create a new python file 40 00:01:25.310 --> 00:01:27.740 actual challenge then you can get i'm just going to paste in the 41 00:01:27.740 --> 00:01:29.720 started I'm going to right-click over actual challenge then you can get 42 00:01:29.720 --> 00:01:32.930 here and i've created a new project and started I'm going to right-click over 43 00:01:32.930 --> 00:01:35.450 select python file and we'll call this here and i've created a new project and 44 00:01:35.450 --> 00:01:38.200 one select python file and we'll call this 45 00:01:38.200 --> 00:01:42.579 challenge and we're going to paste in one 46 00:01:42.579 --> 00:01:44.530 the challenge challenge and we're going to paste in 47 00:01:44.530 --> 00:01:47.079 ok so the challenge is to create a the challenge 48 00:01:47.079 --> 00:01:49.210 program that takes an IP address ok so the challenge is to create a 49 00:01:49.210 --> 00:01:52.329 entered at the keyboard and prints out the program that takes an IP address 50 00:01:52.329 --> 00:01:55.420 number of segments that contains and the entered at the keyboard and prints out the 51 00:01:55.420 --> 00:01:57.189 length of each segment number of segments that contains and the 52 00:01:57.189 --> 00:01:59.619 now an IP address consists of four numbers length of each segment 53 00:01:59.619 --> 00:02:01.630 separated from each other with a full now an IP address consists of four numbers 54 00:02:01.630 --> 00:02:02.530 stop separated from each other with a full 55 00:02:02.530 --> 00:02:04.360 but your program should just count stop 56 00:02:04.360 --> 00:02:06.189 however many have been entered in but your program should just count 57 00:02:06.189 --> 00:02:07.990 examples of the input you may get are however many have been entered in 58 00:02:07.990 --> 00:02:11.230 you can see their 127 . 0 . 0 . 1 examples of the input you may get are 59 00:02:11.230 --> 00:02:15.160 another one with a dot 192 . 168 . you can see their 127 . 0 . 0 . 1 60 00:02:15.160 --> 00:02:19.180 0 . 1 another 1 10 . 0 . 123456 . 255 another one with a dot 192 . 168 . 61 00:02:19.180 --> 00:02:24.700 then 172 . 16 and finally 255 another 0 . 1 another 1 10 . 0 . 123456 . 255 62 00:02:24.700 --> 00:02:26.230 words you program should work even with then 172 . 16 and finally 255 another 63 00:02:26.230 --> 00:02:29.079 invalid IP addresses what we hear words you program should work even with 64 00:02:29.079 --> 00:02:30.519 interested in here is the number of invalid IP addresses what we hear 65 00:02:30.519 --> 00:02:33.549 segments and how long each one is now interested in here is the number of 66 00:02:33.549 --> 00:02:35.829 once you've got a working program here are segments and how long each one is now 67 00:02:35.829 --> 00:02:37.569 some more suggestions for invalid input once you've got a working program here are 68 00:02:37.569 --> 00:02:39.940 to test and i'm not going to read some more suggestions for invalid input 69 00:02:39.940 --> 00:02:41.290 those out but you can see them down there or to test and i'm not going to read 70 00:02:41.290 --> 00:02:42.250 you can see them on the screen there those out but you can see them down there or 71 00:02:42.250 --> 00:02:45.220 from line 17 to 21 not forgetting line you can see them on the screen there 72 00:02:45.220 --> 00:02:47.650 22 which is basically pressing enter from line 17 to 21 not forgetting line 73 00:02:47.650 --> 00:02:49.630 without typing anything making sure your 22 which is basically pressing enter 74 00:02:49.630 --> 00:02:52.150 handling that scenario as well so this without typing anything making sure your 75 00:02:52.150 --> 00:02:53.920 challenge is intended to practice for handling that scenario as well so this 76 00:02:53.920 --> 00:02:56.350 loops and if-else statements so although challenge is intended to practice for 77 00:02:56.350 --> 00:02:58.450 you could use other techniques such as loops and if-else statements so although 78 00:02:58.450 --> 00:02:59.829 splitting the string up you could use other techniques such as 79 00:02:59.829 --> 00:03:01.090 that's not the approach we're looking splitting the string up 80 00:03:01.090 --> 00:03:03.579 for here alright so that's the challenge that's not the approach we're looking 81 00:03:03.579 --> 00:03:04.750 see how you go with that for here alright so that's the challenge 82 00:03:04.750 --> 00:03:06.670 pause the video I'll see you when you see how you go with that 83 00:03:06.670 --> 00:03:12.250 get back ok so let's get started and pause the video I'll see you when you 84 00:03:12.250 --> 00:03:15.850 just a note here that is probably as get back ok so let's get started and 85 00:03:15.850 --> 00:03:17.590 many different solutions to this as just a note here that is probably as 86 00:03:17.590 --> 00:03:19.690 there are people trying to solve it so the many different solutions to this as 87 00:03:19.690 --> 00:03:21.489 test is not that your solutions should there are people trying to solve it so the 88 00:03:21.489 --> 00:03:23.109 look like on what I'm about to present test is not that your solutions should 89 00:03:23.109 --> 00:03:25.720 but rather that it produces the correct look like on what I'm about to present 90 00:03:25.720 --> 00:03:26.739 output but rather that it produces the correct 91 00:03:26.739 --> 00:03:28.900 even if provided with invalid input output 92 00:03:28.900 --> 00:03:30.849 alright so let's get started I'm going even if provided with invalid input 93 00:03:30.849 --> 00:03:34.209 to start with IP address..... alright so let's get started I'm going 94 00:03:34.209 --> 00:03:37.830 .... to start with IP address..... 95 00:03:37.830 --> 00:03:43.410 .... .... 96 00:03:43.410 --> 00:03:48.990 ... .... 97 00:03:48.990 --> 00:03:50.640 so we start by getting the IP address from the ... 98 00:03:50.640 --> 00:03:52.620 user and then we are initializing two so we start by getting the IP address from the 99 00:03:52.620 --> 00:03:54.990 variables now each time we find a full user and then we are initializing two 100 00:03:54.990 --> 00:03:57.390 stop or period in the input string variables now each time we find a full 101 00:03:57.390 --> 00:03:59.700 we're going to increment a counter of stop or period in the input string 102 00:03:59.700 --> 00:04:02.310 how many segments there are now unless we're going to increment a counter of 103 00:04:02.310 --> 00:04:03.750 the input is blank how many segments there are now unless 104 00:04:03.750 --> 00:04:05.100 they'll always be at least one segment the input is blank 105 00:04:05.100 --> 00:04:07.350 we're going to initialize the variable they'll always be at least one segment 106 00:04:07.350 --> 00:04:08.850 segment to a one we're going to initialize the variable 107 00:04:08.850 --> 00:04:11.100 you can see me doing that on line 30 now segment to a one 108 00:04:11.100 --> 00:04:12.210 we're also going to count how many you can see me doing that on line 30 now 109 00:04:12.210 --> 00:04:14.640 characters are in each segment so the we're also going to count how many 110 00:04:14.640 --> 00:04:16.170 variable-length will be used for that characters are in each segment so the 111 00:04:16.170 --> 00:04:18.900 now do be careful with the name of this variable-length will be used for that 112 00:04:18.900 --> 00:04:21.239 variable it may be tempting to use a now do be careful with the name of this 113 00:04:21.239 --> 00:04:23.850 shorthand name for example Len LEN variable it may be tempting to use a 114 00:04:23.850 --> 00:04:26.580 but if you do that your len variable shorthand name for example Len LEN 115 00:04:26.580 --> 00:04:28.980 would actually replace the built-in Len but if you do that your len variable 116 00:04:28.980 --> 00:04:30.870 function and you'll get some weird would actually replace the built-in Len 117 00:04:30.870 --> 00:04:33.180 problems now we do function and you'll get some weird 118 00:04:33.180 --> 00:04:34.290 fortunately get a warning from problems now we do 119 00:04:34.290 --> 00:04:36.450 intelliJ if we try to do that so i fortunately get a warning from 120 00:04:36.450 --> 00:04:38.190 rename this over here to len intelliJ if we try to do that so i 121 00:04:38.190 --> 00:04:40.590 temporarily you can see we've got an rename this over here to len 122 00:04:40.590 --> 00:04:42.810 underline showing their i can highlight temporarily you can see we've got an 123 00:04:42.810 --> 00:04:45.300 that this is shadows built-in name len underline showing their i can highlight 124 00:04:45.300 --> 00:04:46.470 and I can come over here click on more that this is shadows built-in name len 125 00:04:46.470 --> 00:04:50.370 shadows built-in named len and over here and I can come over here click on more 126 00:04:50.370 --> 00:04:51.660 we get the shadows built-in named len and over here 127 00:04:51.660 --> 00:04:54.630 same warning over here that we get the 128 00:04:54.630 --> 00:04:56.520 shadowing the built in name same warning over here that 129 00:04:56.520 --> 00:04:58.410 so what that basically means is we're shadowing the built in name 130 00:04:58.410 --> 00:05:00.870 providing another function for the word so what that basically means is we're 131 00:05:00.870 --> 00:05:03.000 len here overriding the original one providing another function for the word 132 00:05:03.000 --> 00:05:04.260 and that's certainly not what we want to len here overriding the original one 133 00:05:04.260 --> 00:05:06.270 happen here so make sure you do watch and that's certainly not what we want to 134 00:05:06.270 --> 00:05:08.100 out for warnings like that because you happen here so make sure you do watch 135 00:05:08.100 --> 00:05:10.320 can lose the ability to use built in out for warnings like that because you 136 00:05:10.320 --> 00:05:12.810 functions if you reuse the same name in can lose the ability to use built in 137 00:05:12.810 --> 00:05:14.400 your code we certainly don't want to do functions if you reuse the same name in 138 00:05:14.400 --> 00:05:17.220 that and in fact looking at that your code we certainly don't want to do 139 00:05:17.220 --> 00:05:18.419 probably a better name would be that and in fact looking at that 140 00:05:18.419 --> 00:05:21.000 something like segment..... probably a better name would be 141 00:05:21.000 --> 00:05:24.150 we can use len their if you wanted to i'm going something like segment..... 142 00:05:24.150 --> 00:05:26.190 to use...that makes a we can use len their if you wanted to i'm going 143 00:05:26.190 --> 00:05:27.840 lot more sense so we're going to use that to use...that makes a 144 00:05:27.840 --> 00:05:30.270 name instead alright so the next step lot more sense so we're going to use that 145 00:05:30.270 --> 00:05:32.370 now is to loop through all the name instead alright so the next step 146 00:05:32.370 --> 00:05:34.500 characters in the input string IP now is to loop through all the 147 00:05:34.500 --> 00:05:36.840 address and check to see if you've got a characters in the input string IP 148 00:05:36.840 --> 00:05:38.700 full stop or some other character address and check to see if you've got a 149 00:05:38.700 --> 00:05:42.060 let's add the code for that it's going full stop or some other character 150 00:05:42.060 --> 00:05:45.470 make a bit of a space here let's add the code for that it's going 151 00:05:45.470 --> 00:05:46.940 ok so we're going to start with four make a bit of a space here 152 00:05:46.940 --> 00:05:51.410 character in IP address ok so we're going to start with four 153 00:05:51.410 --> 00:05:54.230 .... character in IP address 154 00:05:54.230 --> 00:06:23.660 .... .... 155 00:06:23.660 --> 00:06:28.040 .....if we get to a full stop which as a .... 156 00:06:28.040 --> 00:06:29.840 student pointed out is called a period .....if we get to a full stop which as a 157 00:06:29.840 --> 00:06:32.090 almost everywhere else outside australia student pointed out is called a period 158 00:06:32.090 --> 00:06:34.520 in the UK and that signals the end of almost everywhere else outside australia 159 00:06:34.520 --> 00:06:36.290 the segment and the start of a new one in the UK and that signals the end of 160 00:06:36.290 --> 00:06:39.410 so again I often referred to a period the segment and the start of a new one 161 00:06:39.410 --> 00:06:40.460 as a full stop so again I often referred to a period 162 00:06:40.460 --> 00:06:42.650 they're both the same thing but in any as a full stop 163 00:06:42.650 --> 00:06:44.660 event if we get to this full stop / they're both the same thing but in any 164 00:06:44.660 --> 00:06:46.970 period then that signals the end of the event if we get to this full stop / 165 00:06:46.970 --> 00:06:48.800 segment as I mention and then we start a new period then that signals the end of the 166 00:06:48.800 --> 00:06:51.290 one at that point now on line 35 segment as I mention and then we start a new 167 00:06:51.290 --> 00:06:52.820 we're printing out the details of the one at that point now on line 35 168 00:06:52.820 --> 00:06:54.590 previous segment and then we increment we're printing out the details of the 169 00:06:54.590 --> 00:06:57.169 our segment counter now because we're previous segment and then we increment 170 00:06:57.169 --> 00:06:58.669 about to start reading the characters in our segment counter now because we're 171 00:06:58.669 --> 00:07:00.560 a new segment at that point we're also about to start reading the characters in 172 00:07:00.560 --> 00:07:02.720 taking the opportunity to set the segment_ a new segment at that point we're also 173 00:07:02.720 --> 00:07:05.390 length variable to 0 now if the taking the opportunity to set the segment_ 174 00:07:05.390 --> 00:07:07.940 character isn't a period or a full stop if length variable to 0 now if the 175 00:07:07.940 --> 00:07:09.590 you speak English proper like what I do character isn't a period or a full stop if 176 00:07:09.590 --> 00:07:12.410 then we just increment the count of you speak English proper like what I do 177 00:07:12.410 --> 00:07:14.510 the length so how do we do that we're then we just increment the count of 178 00:07:14.510 --> 00:07:18.860 going to add an else their so..... the length so how do we do that we're 179 00:07:18.860 --> 00:07:21.350 .... going to add an else their so..... 180 00:07:21.350 --> 00:07:24.380 looking that code it looks like it might .... 181 00:07:24.380 --> 00:07:27.380 just work but it doesn't quiet but when looking that code it looks like it might 182 00:07:27.380 --> 00:07:28.790 you're learning it's a good idea to run just work but it doesn't quiet but when 183 00:07:28.790 --> 00:07:30.890 your code as you build it up that way you're learning it's a good idea to run 184 00:07:30.890 --> 00:07:32.300 you get to see the problems with your your code as you build it up that way 185 00:07:32.300 --> 00:07:34.340 logic before you've written to much and you get to see the problems with your 186 00:07:34.340 --> 00:07:36.860 can make adjustments so I actually run logic before you've written to much and 187 00:07:36.860 --> 00:07:38.510 this program now gonna start by right can make adjustments so I actually run 188 00:07:38.510 --> 00:07:41.690 clicking it click on run challenge i'm this program now gonna start by right 189 00:07:41.690 --> 00:07:42.919 going to move this down to the bottom so clicking it click on run challenge i'm 190 00:07:42.919 --> 00:07:47.600 you can see it a bit easier it's asking going to move this down to the bottom so 191 00:07:47.600 --> 00:07:50.240 for an IP address if I actually type this you can see it a bit easier it's asking 192 00:07:50.240 --> 00:07:52.790 ....and for an IP address if I actually type this 193 00:07:52.790 --> 00:07:53.570 press enter ....and 194 00:07:53.570 --> 00:07:56.900 you can see we've got segment one press enter 195 00:07:56.900 --> 00:07:58.669 contains one character segments 2 you can see we've got segment one 196 00:07:58.669 --> 00:07:59.120 contain contains one character segments 2 197 00:07:59.120 --> 00:08:01.639 one segment 3 contains one but it's contain 198 00:08:01.639 --> 00:08:03.560 missed the last one so i'm looking at one segment 3 contains one but it's 199 00:08:03.560 --> 00:08:07.340 the code we see that only prints out the missed the last one so i'm looking at 200 00:08:07.340 --> 00:08:09.740 details for a segment when it finds the the code we see that only prints out the 201 00:08:09.740 --> 00:08:10.610 full stop details for a segment when it finds the 202 00:08:10.610 --> 00:08:13.280 sorry period that terminates it so the full stop 203 00:08:13.280 --> 00:08:15.560 final segment isn't terminated by period sorry period that terminates it so the 204 00:08:15.560 --> 00:08:18.199 so as a consequence it doesn't get final segment isn't terminated by period 205 00:08:18.199 --> 00:08:19.100 printed so as a consequence it doesn't get 206 00:08:19.100 --> 00:08:21.199 now there's a clever and slightly printed 207 00:08:21.199 --> 00:08:23.690 sneaky way to handle that but i'll start now there's a clever and slightly 208 00:08:23.690 --> 00:08:25.970 by doing it the obvious way what we need sneaky way to handle that but i'll start 209 00:08:25.970 --> 00:08:28.460 to do is add an extra bit of code by doing it the obvious way what we need 210 00:08:28.460 --> 00:08:30.949 after loop to check to see if the last to do is add an extra bit of code 211 00:08:30.949 --> 00:08:32.810 name was a period and print out the after loop to check to see if the last 212 00:08:32.810 --> 00:08:35.719 final segment details if it wasn't going name was a period and print out the 213 00:08:35.719 --> 00:08:37.880 to come down here to do that on line 41 final segment details if it wasn't going 214 00:08:37.880 --> 00:08:40.940 jut a note here.... to come down here to do that on line 41 215 00:08:40.940 --> 00:08:44.630 .... jut a note here.... 216 00:08:44.630 --> 00:08:52.220 .... .... 217 00:08:52.220 --> 00:08:59.570 and then the actual code will be if.... .... 218 00:08:59.570 --> 00:09:04.040 ..... and then the actual code will be if.... 219 00:09:04.040 --> 00:09:05.300 .... ..... 220 00:09:05.300 --> 00:09:08.660 .... .... 221 00:09:08.660 --> 00:09:11.690 ....now if we run this again .... 222 00:09:11.690 --> 00:09:17.120 ....we can ....now if we run this again 223 00:09:17.120 --> 00:09:18.680 see that it's now handling that fourth ....we can 224 00:09:18.680 --> 00:09:20.540 fourth number correctly see that it's now handling that fourth 225 00:09:20.540 --> 00:09:24.410 alright so now it's a good opportunity to fourth number correctly 226 00:09:24.410 --> 00:09:26.690 start testing the various inputs alright so now it's a good opportunity to 227 00:09:26.690 --> 00:09:28.940 that I listed in the challenge so I got them start testing the various inputs 228 00:09:28.940 --> 00:09:30.890 all listed up here let's just go through that I listed in the challenge so I got them 229 00:09:30.890 --> 00:09:32.810 those one by one we tested the first one all listed up here let's just go through 230 00:09:32.810 --> 00:09:34.730 we'll start with the first one... those one by one we tested the first one 231 00:09:34.730 --> 00:09:38.900 ....you can see we got the right we'll start with the first one... 232 00:09:38.900 --> 00:09:41.959 inputs for their 3111 which is correct ....you can see we got the right 233 00:09:41.959 --> 00:09:44.540 run it again this time we'll try typing... inputs for their 3111 which is correct 234 00:09:44.540 --> 00:09:49.760 we actually got run it again this time we'll try typing... 235 00:09:49.760 --> 00:09:53.360 five segments the first one 0 33 11 we actually got 236 00:09:53.360 --> 00:09:57.320 okay next so far so good.... five segments the first one 0 33 11 237 00:09:57.320 --> 00:10:03.350 ....and that should be 216 and okay next so far so good.... 238 00:10:03.350 --> 00:10:04.459 three in terms of the number of ....and that should be 216 and 239 00:10:04.459 --> 00:10:06.470 characters in each segment that's three in terms of the number of 240 00:10:06.470 --> 00:10:07.430 correct characters in each segment that's 241 00:10:07.430 --> 00:10:10.490 ok let's try another one let's try.... correct 242 00:10:10.490 --> 00:10:11.670 .... ok let's try another one let's try.... 243 00:10:11.670 --> 00:10:15.630 three and two that's correct .... 244 00:10:15.630 --> 00:10:18.330 we will try one with just a number 255 three and two that's correct 245 00:10:18.330 --> 00:10:22.860 segment one contains three characters so we will try one with just a number 255 246 00:10:22.860 --> 00:10:23.910 far so good segment one contains three characters so 247 00:10:23.910 --> 00:10:27.270 ok next one was.... far so good 248 00:10:27.270 --> 00:10:33.960 ....0 ok next one was.... 249 00:10:33.960 --> 00:10:36.990 32 32 in terms of number of characters ....0 250 00:10:36.990 --> 00:10:39.060 for each segment which is correct 32 32 in terms of number of characters 251 00:10:39.060 --> 00:10:45.390 alright so..... for each segment which is correct 252 00:10:45.390 --> 00:10:52.800 ....we got 3411 there and we'll try alright so..... 253 00:10:52.800 --> 00:10:58.350 big one...... ....we got 3411 there and we'll try 254 00:10:58.350 --> 00:11:05.370 ....33 and 9 and got two more to do big one...... 255 00:11:05.370 --> 00:11:09.720 here to test.... ....33 and 9 and got two more to do 256 00:11:09.720 --> 00:11:14.640 ...232 and the very last one now here to test.... 257 00:11:14.640 --> 00:11:19.110 .... ...232 and the very last one now 258 00:11:19.110 --> 00:11:23.550 ....212 122 .... 259 00:11:23.550 --> 00:11:24.990 so everything seems to be working ....212 122 260 00:11:24.990 --> 00:11:27.570 fine theirs only one last test to do now so everything seems to be working 261 00:11:27.570 --> 00:11:29.340 which is to enter nothing i'm going to fine theirs only one last test to do now 262 00:11:29.340 --> 00:11:31.020 start again and press ENTER which is to enter nothing i'm going to 263 00:11:31.020 --> 00:11:35.550 and we get an error that isn't good this start again and press ENTER 264 00:11:35.550 --> 00:11:37.020 error happens because there's no and we get an error that isn't good this 265 00:11:37.020 --> 00:11:39.450 characters and IP address and that means error happens because there's no 266 00:11:39.450 --> 00:11:40.800 that the for loop that we starting characters and IP address and that means 267 00:11:40.800 --> 00:11:43.410 on line 33 doesn't have any values to that the for loop that we starting 268 00:11:43.410 --> 00:11:45.540 iterate over and consequently the on line 33 doesn't have any values to 269 00:11:45.540 --> 00:11:47.280 variable character is never assigned a iterate over and consequently the 270 00:11:47.280 --> 00:11:50.190 value and in fact IntelliJ is aware variable character is never assigned a 271 00:11:50.190 --> 00:11:51.390 that this might happen and it's actually value and in fact IntelliJ is aware 272 00:11:51.390 --> 00:11:53.640 getting this warning down here if you that this might happen and it's actually 273 00:11:53.640 --> 00:11:56.040 hover over that name character may not getting this warning down here if you 274 00:11:56.040 --> 00:12:00.270 be defined now any Java or C++ programmer hover over that name character may not 275 00:12:00.270 --> 00:12:01.500 is watching this would have been be defined now any Java or C++ programmer 276 00:12:01.500 --> 00:12:04.860 horrified that I type that final if is watching this would have been 277 00:12:04.860 --> 00:12:06.930 statement in the first place in those horrified that I type that final if 278 00:12:06.930 --> 00:12:08.820 languages character would never be statement in the first place in those 279 00:12:08.820 --> 00:12:11.460 accessible outside of the for loop but languages character would never be 280 00:12:11.460 --> 00:12:13.440 in Python that's perfectly acceptable to accessible outside of the for loop but 281 00:12:13.440 --> 00:12:16.560 do but only if the for loop is guaranteed to in Python that's perfectly acceptable to 282 00:12:16.560 --> 00:12:18.540 execute at least once do but only if the for loop is guaranteed to 283 00:12:18.540 --> 00:12:20.730 as long as the loop is entered the execute at least once 284 00:12:20.730 --> 00:12:23.190 variable character will have a value and as long as the loop is entered the 285 00:12:23.190 --> 00:12:24.960 that value will be available outside of variable character will have a value and 286 00:12:24.960 --> 00:12:25.209 the loop that value will be available outside of 287 00:12:25.209 --> 00:12:27.910 but the problem here is that the loop the loop 288 00:12:27.910 --> 00:12:29.350 didn't execute at all but the problem here is that the loop 289 00:12:29.350 --> 00:12:30.730 that's because there were no characters didn't execute at all 290 00:12:30.730 --> 00:12:33.610 in IP address to loop over there is a that's because there were no characters 291 00:12:33.610 --> 00:12:35.829 relatively easy fix here that's just to in IP address to loop over there is a 292 00:12:35.829 --> 00:12:37.869 initialize character to be an empty relatively easy fix here that's just to 293 00:12:37.869 --> 00:12:39.819 string at the same time as we initialize initialize character to be an empty 294 00:12:39.819 --> 00:12:41.410 the other variables string at the same time as we initialize 295 00:12:41.410 --> 00:12:45.490 let's go up and do that so..... the other variables 296 00:12:45.490 --> 00:12:49.480 ...and incidentally let's go up and do that so..... 297 00:12:49.480 --> 00:12:51.040 I use double quotes there ...and incidentally 298 00:12:51.040 --> 00:12:53.259 because 2 single quotes can appear as I use double quotes there 299 00:12:53.259 --> 00:12:55.540 one double quote on the video but you because 2 single quotes can appear as 300 00:12:55.540 --> 00:12:58.179 could actually use 2 single quotes like one double quote on the video but you 301 00:12:58.179 --> 00:13:00.850 that again video may not shown to clearly could actually use 2 single quotes like 302 00:13:00.850 --> 00:13:02.800 i'm using two double quotes both that again video may not shown to clearly 303 00:13:02.800 --> 00:13:03.970 are the same result i'm using two double quotes both 304 00:13:03.970 --> 00:13:05.889 the important thing now is that the are the same result 305 00:13:05.889 --> 00:13:08.829 variable character has a value whether the important thing now is that the 306 00:13:08.829 --> 00:13:11.619 the for loop runs or not so this time variable character has a value whether 307 00:13:11.619 --> 00:13:15.160 when i run the program and press ENTER the for loop runs or not so this time 308 00:13:15.160 --> 00:13:18.579 segment one contains zero characters we when i run the program and press ENTER 309 00:13:18.579 --> 00:13:21.249 get the correct result I won't spend any segment one contains zero characters we 310 00:13:21.249 --> 00:13:22.629 more time in this video running through all get the correct result I won't spend any 311 00:13:22.629 --> 00:13:24.730 the other tests again try them out more time in this video running through all 312 00:13:24.730 --> 00:13:26.649 and they will all actually work fine the other tests again try them out 313 00:13:26.649 --> 00:13:28.809 so that's the solution if your solution and they will all actually work fine 314 00:13:28.809 --> 00:13:30.699 works with the same amount of input so that's the solution if your solution 315 00:13:30.699 --> 00:13:33.040 getting the same results congratulations works with the same amount of input 316 00:13:33.040 --> 00:13:34.629 but remember again that there are many getting the same results congratulations 317 00:13:34.629 --> 00:13:36.939 ways to solve a problem so your code may but remember again that there are many 318 00:13:36.939 --> 00:13:39.100 be very different to mine the important ways to solve a problem so your code may 319 00:13:39.100 --> 00:13:40.569 thing here is that isn't that you've got be very different to mine the important 320 00:13:40.569 --> 00:13:42.759 the same code but that it produces the thing here is that isn't that you've got 321 00:13:42.759 --> 00:13:43.779 same results the same code but that it produces the 322 00:13:43.779 --> 00:13:46.209 alright I'm going to finish the video same results 323 00:13:46.209 --> 00:13:48.220 here now in the next video I want to alright I'm going to finish the video 324 00:13:48.220 --> 00:13:49.990 talk about that sneaky method that i here now in the next video I want to 325 00:13:49.990 --> 00:13:52.629 mentioned earlier this video involves talk about that sneaky method that i 326 00:13:52.629 --> 00:13:54.069 thinking about things slightly mentioned earlier this video involves 327 00:13:54.069 --> 00:13:56.589 differently and a clue is in the that thinking about things slightly 328 00:13:56.589 --> 00:13:58.389 comment that i added before the final differently and a clue is in the that 329 00:13:58.389 --> 00:14:00.910 if statement this part down here unless the comment that i added before the final 330 00:14:00.910 --> 00:14:03.009 final character in string was a if statement this part down here unless the 331 00:14:03.009 --> 00:14:05.199 period so let's look at that in the next final character in string was a 332 00:14:05.199 --> 00:14:10.619 video period so let's look at that in the next