1
00:00:05,280 --> 00:00:08,550
so in this video we are going to do a
challenge I'm gonna challenge you to

2
00:00:08,550 --> 00:00:13,660
complete a particular challenge for this
section of the course which is of course

3
00:00:13,660 --> 00:00:18,560
dealing with time zone and what I'm gonna
do is paste it in and talk about it

4
00:00:18,560 --> 00:00:22,430
and then get you to actually do the
challenge so first things first is create a

5
00:00:22,430 --> 00:00:27,530
new file here I got the same project
open as last time right click on that

6
00:00:27,530 --> 00:00:36,870
new Python file I'm gonna call it timechallenge
that is the timezone challenge going to paste the code in

7
00:00:36,870 --> 00:00:42,460
so let's go
through and discuss what the challenge

8
00:00:42,460 --> 00:00:48,990
is and essentially I'm asking you to create a
program that allows a user of your

9
00:00:48,990 --> 00:00:53,140
program to choose one of up to nine
different time zones from a menu you

10
00:00:53,140 --> 00:00:57,400
can choose any zone you want from the
all_timezones list that's going to be

11
00:00:57,400 --> 00:01:01,960
where you save the time zones for
this program and the program will then

12
00:01:01,960 --> 00:01:07,870
display the time in that time zone as
well as local time and UTC time entering

13
00:01:07,870 --> 00:01:12,090
0 choice from the menu will quit
the program so you want to display the dates and

14
00:01:12,090 --> 00:01:17,140
times in a format suitable for the user
of your program to understand and you should also

15
00:01:17,140 --> 00:01:21,850
include the timezone name when
displaying the chosen name so that's it

16
00:01:21,850 --> 00:01:27,280
that's the challenge so I suggest you do
now is go away and see if you can solve that and

17
00:01:27,280 --> 00:01:31,670
when you're ready to come back you can come
back and check our solution and take

18
00:01:31,670 --> 00:01:39,750
it from their so pause the video now and
I'll see you when you get back

19
00:01:39,750 --> 00:01:45,140
hopefully you managed to get this working or
have a good stab at it any way so lets go through now

20
00:01:45,140 --> 00:01:49,910
our implementation and see if its something
similar to what you came up with so

21
00:01:49,910 --> 00:01:56,950
first we need to do our 2 imports from modules which we have been doing....

22
00:01:56,950 --> 00:02:00,380
.....

23
00:02:00,380 --> 00:02:08,470
.....so next we need all the time
zones lists where we can choose where we can

24
00:02:08,470 --> 00:02:11,870
choose from up to nine times and so what
we're going to do is create that so....

25
00:02:11,870 --> 00:02:16,990
.....

26
00:02:16,990 --> 00:02:23,220
.....and I'm gonna start with one
that's gonna be the choice for the menu you don't

27
00:02:23,220 --> 00:02:27,380
have to strictly use these
that I come up with as long as you got

28
00:02:27,380 --> 00:02:43,550
separate ones......also get the spelling on these correct because

29
00:02:43,550 --> 00:02:55,750
if their wrong and they don't match the time zone
you get a problem....

30
00:02:55,750 --> 00:03:32,360
.....

31
00:03:32,360 --> 00:03:39,350
...so that's

32
00:03:39,350 --> 00:03:46,170
our available list of nine options so what
we want to do now is accept input from

33
00:03:46,170 --> 00:03:51,140
that and then start displaying it so
first things first lets print a message that

34
00:03:51,140 --> 00:03:59,920
people see on the screen so... which we mentioned was

35
00:03:59,920 --> 00:04:11,540
part of the instructions there.....

36
00:04:11,540 --> 00:04:14,630
.....

37
00:04:14,630 --> 00:04:21,329
......

38
00:04:21,329 --> 00:04:26,540
....the format began to include
the place which was obviously from the

39
00:04:26,540 --> 00:04:29,690
list and also available_zones....

40
00:04:29,690 --> 00:04:36,660
...so we are getting the number as well as the actual location so

41
00:04:36,660 --> 00:04:41,040
that's our loop to display them on the
screen and what we're doing now is

42
00:04:41,040 --> 00:04:46,480
work on the loop that accepts input from
the user and continues to loop until I press 0

43
00:04:46,480 --> 00:04:54,700
so put...so its going to continue
looping until I enter 0 to exit...

44
00:04:54,700 --> 00:05:01,940
.....

45
00:05:01,940 --> 00:05:07,660
....

46
00:05:07,660 --> 00:05:11,650
...so that's going to break out of the while loop and end the program but if

47
00:05:11,650 --> 00:05:15,910
we're not exited then what we need to do is we need
to look up and see whether the choice

48
00:05:15,910 --> 00:05:20,730
entered is in the keys so the way to do that is...

49
00:05:20,730 --> 00:05:26,640
.....so
in other words if the number 1 to 9 has that

50
00:05:26,640 --> 00:05:32,480
been entered if it isn't there we are gonna put....

51
00:05:32,480 --> 00:05:40,750
.....

52
00:05:40,750 --> 00:05:46,970
......

53
00:05:46,970 --> 00:05:58,950
.......

54
00:05:58,950 --> 00:06:21,320
.....

55
00:06:21,320 --> 00:06:29,980
....and we're going to format that to a proper

56
00:06:29,980 --> 00:06:34,840
time we talked about that on line 10 display dates and times in a format

57
00:06:34,840 --> 00:06:37,890
suitable for the uses of your program to
understand so we've done this before we are gonna do

58
00:06:37,890 --> 00:06:38,500
something similar

59
00:06:38,500 --> 00:06:41,590
we are....

60
00:06:41,590 --> 00:06:54,350
.....

61
00:06:54,350 --> 00:07:00,220
....

62
00:07:00,220 --> 00:07:10,220
.....so that's the first one

63
00:07:10,220 --> 00:07:16,280
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:16,280 --> 00:07:23,920
ahead and do that and it's going to be.....the local time is of course the local

65
00:07:23,920 --> 00:07:27,310
time in which ever time zone your
currently running this in for me its gonna

66
00:07:27,310 --> 00:07:32,300
Australian central
Daylight Time format and it's going to

67
00:07:32,300 --> 00:07:40,800
be..... we are going to use basically the same format very similar format

68
00:07:40,800 --> 00:07:46,980
and we are going to use...to get the current time but then
format the actual time so...

69
00:07:46,980 --> 00:07:49,390
.....

70
00:07:49,390 --> 00:07:56,990
....

71
00:07:56,990 --> 00:08:04,960
.....

72
00:08:04,960 --> 00:08:09,800
.....and the difference there is
we're going to use instead of now we're

73
00:08:09,800 --> 00:08:14,400
going to use UTC now to get the current
UTC time and everything should be the

74
00:08:14,400 --> 00:08:19,280
same and add one last final print to space it out a bit in the end and that should

75
00:08:19,280 --> 00:08:23,820
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:23,820 --> 00:08:29,600
Python way of doing things and now we've
done that we should find that we're good

77
00:08:29,600 --> 00:08:30,090
to go

78
00:08:30,090 --> 00:08:33,659
what would do first is try
running it right click and run time

79
00:08:33,659 --> 00:08:38,900
challenge you can see we've currently got
the menu showing please choose a time zones or 0

80
00:08:38,900 --> 00:08:44,590
to quit so type 0 to quit to make sure that works ok that work well

81
00:08:44,590 --> 00:08:50,350
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:50,350 --> 00:08:54,680
Adelaide and we got an error on line 38 now
we just have a look at that error

83
00:08:54,680 --> 00:09:01,960
unknown time zone and the reason
that's unknown is up typed Australian

84
00:09:01,960 --> 00:09:06,510
instead of Adeliade how embarrassing my own timezone
so that should be

85
00:09:06,510 --> 00:09:10,120
Australia Adelaide remember earlier in
the challenge in this video I mentioned

86
00:09:10,120 --> 00:09:15,550
the need to not make any typos and of course
is another one on line 4 in my haste to

87
00:09:15,550 --> 00:09:20,080
try and dp this video and type of the
same time I seem to be failing at task

88
00:09:20,080 --> 00:09:23,830
need to make sure that you fixed the typos to have any chance of this working

89
00:09:23,830 --> 00:09:26,180
lets try it again number 3

90
00:09:26,180 --> 00:09:31,270
Australia / Adelaide this time and we actually
got something which is good and we have

91
00:09:31,270 --> 00:09:35,730
a look at our time wednesday at 1:40
which is converted to 1:49 their because you can see

92
00:09:35,730 --> 00:09:37,440
it was on 55 seconds

93
00:09:37,440 --> 00:09:42,990
UTC time is second of the third sixty
you can see the format we used and noticed

94
00:09:42,990 --> 00:09:50,980
before when I look at the code we did the %z for the first line and

95
00:09:50,980 --> 00:09:54,440
then we can see that by doing that we
added the time zone information the

96
00:09:54,440 --> 00:09:57,710
extra information that's appearing on
this first line the others lines have also

97
00:09:57,710 --> 00:10:03,300
got the current day and then the date month and year and time but we also added

98
00:10:03,300 --> 00:10:07,740
timezone and that's what the other entry was so that's working ok so lets try a couple

99
00:10:07,740 --> 00:10:14,800
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:14,800 --> 00:10:26,900
CET so if we actually do a search for current
time we put current time 4:19 am and its

101
00:10:26,900 --> 00:10:33,210
GMT +1 time in Tunisia which should be
correct obviously and you can see where

102
00:10:33,210 --> 00:10:36,630
+1 there is as well so its definitely
working and just try another

103
00:10:36,630 --> 00:10:43,810
one lets just try 6 Japan current time
in japan is 12:20 and +9 which is JST current time Japan

104
00:10:43,810 --> 00:10:55,240
...you can see currently the time is 12:20 JST time and if you go back and have a

105
00:10:55,240 --> 00:11:04,520
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:04,520 --> 00:11:07,040
so you can see obviously the time zones are
working nicely

107
00:11:07,040 --> 00:11:12,630
lets check that current time Hawaii

108
00:11:12,630 --> 00:11:21,520
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:21,520 --> 00:11:25,670
actually the solution that's the
challenge done and dusted so I hope you

110
00:11:25,670 --> 00:11:30,800
got a lot out of that so we are now done
with time time zones dates etc

111
00:11:30,800 --> 00:11:34,240
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:34,240 --> 00:11:39,400
trip what we gonna do is start
looking or have a brief look at tk enter

113
00:11:39,400 --> 00:11:43,540
this is the tk  widget tool from Python which
allows GUI programs to be created

114
00:11:43,540 --> 00:11:47,120
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:47,120 --> 00:11:51,400
an idea on how to start looking at
GUI interfaces so will start looking

116
00:11:51,400 --> 00:11:52,930
at doing that in the next video

