WEBVTT 1 00:00:01.960 --> 00:00:05.230 so in this video we are going to do a challenge I'm gonna challenge you to 2 00:00:05.230 --> 00:00:10.349 complete a particular challenge for this section of the course which is of course 3 00:00:10.349 --> 00:00:15.240 dealing with time zone and what I'm gonna do is paste it in and talk about it 4 00:00:15.240 --> 00:00:19.119 and then get you to actually do the challenge so first things first is create a 5 00:00:19.119 --> 00:00:24.210 new file here I got the same project open as last time right click on that 6 00:00:24.210 --> 00:00:33.559 new Python file I'm gonna call it timechallenge that is the timezone challenge going to paste the code in 7 00:00:33.559 --> 00:00:39.140 so let's go through and discuss what the challenge 8 00:00:39.140 --> 00:00:45.670 is and essentially I'm asking you to create a program that allows a user of your 9 00:00:45.670 --> 00:00:49.820 program to choose one of up to nine different time zones from a menu you 10 00:00:49.820 --> 00:00:54.089 can choose any zone you want from the all_timezones list that's going to be 11 00:00:54.089 --> 00:00:58.640 where you save the time zones for this program and the program will then 12 00:00:58.640 --> 00:01:04.559 display the time in that time zone as well as local time and UTC time entering 13 00:01:04.559 --> 00:01:08.770 0 choice from the menu will quit the program so you want to display the dates and 14 00:01:08.770 --> 00:01:13.820 times in a format suitable for the user of your program to understand and you should also 15 00:01:13.820 --> 00:01:18.530 include the timezone name when displaying the chosen name so that's it 16 00:01:18.530 --> 00:01:23.969 that's the challenge so I suggest you do now is go away and see if you can solve that and 17 00:01:23.969 --> 00:01:28.350 when you're ready to come back you can come back and check our solution and take 18 00:01:28.350 --> 00:01:36.430 it from their so pause the video now and I'll see you when you get back 19 00:01:36.430 --> 00:01:41.820 hopefully you managed to get this working or have a good stab at it any way so lets go through now 20 00:01:41.820 --> 00:01:46.590 our implementation and see if its something similar to what you came up with so 21 00:01:46.590 --> 00:01:53.630 first we need to do our 2 imports from modules which we have been doing.... 22 00:01:53.630 --> 00:01:57.060 ..... 23 00:01:57.060 --> 00:02:05.159 .....so next we need all the time zones lists where we can choose where we can 24 00:02:05.159 --> 00:02:08.550 choose from up to nine times and so what we're going to do is create that so.... 25 00:02:08.550 --> 00:02:13.670 ..... 26 00:02:13.670 --> 00:02:19.900 .....and I'm gonna start with one that's gonna be the choice for the menu you don't 27 00:02:19.900 --> 00:02:24.069 have to strictly use these that I come up with as long as you got 28 00:02:24.069 --> 00:02:40.230 separate ones......also get the spelling on these correct because 29 00:02:40.230 --> 00:02:52.430 if their wrong and they don't match the time zone you get a problem.... 30 00:02:52.430 --> 00:03:29.040 ..... 31 00:03:29.040 --> 00:03:36.030 ...so that's 32 00:03:36.030 --> 00:03:42.850 our available list of nine options so what we want to do now is accept input from 33 00:03:42.850 --> 00:03:47.820 that and then start displaying it so first things first lets print a message that 34 00:03:47.820 --> 00:03:56.609 people see on the screen so... which we mentioned was 35 00:03:56.609 --> 00:04:08.220 part of the instructions there..... 36 00:04:08.220 --> 00:04:11.310 ..... 37 00:04:11.310 --> 00:04:18.019 ...... 38 00:04:18.019 --> 00:04:23.220 ....the format began to include the place which was obviously from the 39 00:04:23.220 --> 00:04:26.370 list and also available_zones.... 40 00:04:26.370 --> 00:04:33.340 ...so we are getting the number as well as the actual location so 41 00:04:33.340 --> 00:04:37.729 that's our loop to display them on the screen and what we're doing now is 42 00:04:37.729 --> 00:04:43.160 work on the loop that accepts input from the user and continues to loop until I press 0 43 00:04:43.160 --> 00:04:51.389 so put...so its going to continue looping until I enter 0 to exit... 44 00:04:51.389 --> 00:04:58.620 ..... 45 00:04:58.620 --> 00:05:04.340 .... 46 00:05:04.340 --> 00:05:08.330 ...so that's going to break out of the while loop and end the program but if 47 00:05:08.330 --> 00:05:12.590 we're not exited then what we need to do is we need to look up and see whether the choice 48 00:05:12.590 --> 00:05:17.410 entered is in the keys so the way to do that is... 49 00:05:17.410 --> 00:05:23.320 .....so in other words if the number 1 to 9 has that 50 00:05:23.320 --> 00:05:29.169 been entered if it isn't there we are gonna put.... 51 00:05:29.169 --> 00:05:37.430 ..... 52 00:05:37.430 --> 00:05:43.650 ...... 53 00:05:43.650 --> 00:05:55.639 ....... 54 00:05:55.639 --> 00:06:18.000 ..... 55 00:06:18.000 --> 00:06:26.669 ....and we're going to format that to a proper 56 00:06:26.669 --> 00:06:31.520 time we talked about that on line 10 display dates and times in a format 57 00:06:31.520 --> 00:06:34.570 suitable for the uses of your program to understand so we've done this before we are gonna do 58 00:06:34.570 --> 00:06:35.180 something similar 59 00:06:35.180 --> 00:06:38.270 we are.... 60 00:06:38.270 --> 00:06:51.030 ..... 61 00:06:51.030 --> 00:06:56.900 .... 62 00:06:56.900 --> 00:07:06.900 .....so that's the first one 63 00:07:06.900 --> 00:07:12.960 we also want to print out local time so that's part of the challenge as well to do that so lets go 64 00:07:12.960 --> 00:07:20.600 ahead and do that and it's going to be.....the local time is of course the local 65 00:07:20.600 --> 00:07:23.990 time in which ever time zone your currently running this in for me its gonna 66 00:07:23.990 --> 00:07:28.980 Australian central Daylight Time format and it's going to 67 00:07:28.980 --> 00:07:37.480 be..... we are going to use basically the same format very similar format 68 00:07:37.480 --> 00:07:43.660 and we are going to use...to get the current time but then format the actual time so... 69 00:07:43.660 --> 00:07:46.070 ..... 70 00:07:46.070 --> 00:07:53.670 .... 71 00:07:53.670 --> 00:08:01.640 ..... 72 00:08:01.640 --> 00:08:06.480 .....and the difference there is we're going to use instead of now we're 73 00:08:06.480 --> 00:08:11.080 going to use UTC now to get the current UTC time and everything should be the 74 00:08:11.080 --> 00:08:15.960 same and add one last final print to space it out a bit in the end and that should 75 00:08:15.960 --> 00:08:20.500 be it that should be all we need to do and I'll just delete the spaces and leave one space as per the standard 76 00:08:20.500 --> 00:08:26.280 Python way of doing things and now we've done that we should find that we're good 77 00:08:26.280 --> 00:08:26.770 to go 78 00:08:26.770 --> 00:08:30.340 what would do first is try running it right click and run time 79 00:08:30.340 --> 00:08:35.580 challenge you can see we've currently got the menu showing please choose a time zones or 0 80 00:08:35.580 --> 00:08:41.270 to quit so type 0 to quit to make sure that works ok that work well 81 00:08:41.270 --> 00:08:47.030 as we expected to do all right so let's to time zone that we know works lets do 3 for Australian 82 00:08:47.030 --> 00:08:51.360 Adelaide and we got an error on line 38 now we just have a look at that error 83 00:08:51.360 --> 00:08:58.640 unknown time zone and the reason that's unknown is up typed Australian 84 00:08:58.640 --> 00:09:03.190 instead of Adeliade how embarrassing my own timezone so that should be 85 00:09:03.190 --> 00:09:06.800 Australia Adelaide remember earlier in the challenge in this video I mentioned 86 00:09:06.800 --> 00:09:12.230 the need to not make any typos and of course is another one on line 4 in my haste to 87 00:09:12.230 --> 00:09:16.769 try and dp this video and type of the same time I seem to be failing at task 88 00:09:16.769 --> 00:09:20.519 need to make sure that you fixed the typos to have any chance of this working 89 00:09:20.519 --> 00:09:22.860 lets try it again number 3 90 00:09:22.860 --> 00:09:27.950 Australia / Adelaide this time and we actually got something which is good and we have 91 00:09:27.950 --> 00:09:32.410 a look at our time wednesday at 1:40 which is converted to 1:49 their because you can see 92 00:09:32.410 --> 00:09:34.120 it was on 55 seconds 93 00:09:34.120 --> 00:09:39.670 UTC time is second of the third sixty you can see the format we used and noticed 94 00:09:39.670 --> 00:09:47.660 before when I look at the code we did the %z for the first line and 95 00:09:47.660 --> 00:09:51.120 then we can see that by doing that we added the time zone information the 96 00:09:51.120 --> 00:09:54.399 extra information that's appearing on this first line the others lines have also 97 00:09:54.399 --> 00:09:59.980 got the current day and then the date month and year and time but we also added 98 00:09:59.980 --> 00:10:04.420 timezone and that's what the other entry was so that's working ok so lets try a couple 99 00:10:04.420 --> 00:10:11.480 of others to make sure we don't got any problems here 1 the time in Africa Tunis is Wednesday 4:19 a.m. 100 00:10:11.480 --> 00:10:23.589 CET so if we actually do a search for current time we put current time 4:19 am and its 101 00:10:23.589 --> 00:10:29.899 GMT +1 time in Tunisia which should be correct obviously and you can see where 102 00:10:29.899 --> 00:10:33.310 +1 there is as well so its definitely working and just try another 103 00:10:33.310 --> 00:10:40.490 one lets just try 6 Japan current time in japan is 12:20 and +9 which is JST current time Japan 104 00:10:40.490 --> 00:10:51.920 ...you can see currently the time is 12:20 JST time and if you go back and have a 105 00:10:51.920 --> 00:11:01.209 look again 12:20 so that is all working and what the heck of it lets try another Hawaii current time -10 HST 106 00:11:01.209 --> 00:11:03.720 so you can see obviously the time zones are working nicely 107 00:11:03.720 --> 00:11:09.319 lets check that current time Hawaii 108 00:11:09.319 --> 00:11:18.209 5:20 p.m. 2nd of February HST 17:20 which is 5:20 p.m. so that's it that's 109 00:11:18.209 --> 00:11:22.350 actually the solution that's the challenge done and dusted so I hope you 110 00:11:22.350 --> 00:11:27.480 got a lot out of that so we are now done with time time zones dates etc 111 00:11:27.480 --> 00:11:30.920 in the next lecture what we're going to do is we're going to take a little bit of a side ways 112 00:11:30.920 --> 00:11:36.089 trip what we gonna do is start looking or have a brief look at tk enter 113 00:11:36.089 --> 00:11:40.220 this is the tk widget tool from Python which allows GUI programs to be created 114 00:11:40.220 --> 00:11:43.800 so it's not going to be like a huge sort of section on this but it's going to give you 115 00:11:43.800 --> 00:11:48.089 an idea on how to start looking at GUI interfaces so will start looking 116 00:11:48.089 --> 00:11:49.610 at doing that in the next video