1
00:00:05,340 --> 00:00:09,110
Alright, so you can probably guess what the first challenge is here.

2
00:00:09,420 --> 00:00:15,450
At the end of the last video we saw how to use a more complex conditional expression to return one of four values,

3
00:00:15,930 --> 00:00:19,800
fizz, buzz, fizzbuzz or a value.

4
00:00:19,890 --> 00:00:26,030
So the first challenge is to create a list containing the fizzbuzz results, using a list comprehension.

5
00:00:26,070 --> 00:00:28,320
So create a new file, you can see on the screen here,

6
00:00:28,670 --> 00:00:31,390
I've got one that I've called compchallenge1.py

7
00:00:31,770 --> 00:00:37,260
So use the conditional expression from the previous video to produce a list comprehension that returns

8
00:00:37,260 --> 00:00:38,560
the fizzbuzz results.

9
00:00:38,730 --> 00:00:41,270
And again just in more detail, if the number's divisible by 3

10
00:00:41,280 --> 00:00:44,170
the value should be fizz, if it's divisible by 5,

11
00:00:44,190 --> 00:00:47,070
the value should be buzz, if it's divisible by both 3 and 5,

12
00:00:47,070 --> 00:00:48,800
the value should be fizzbuzz.

13
00:00:48,810 --> 00:00:53,520
And finally if none of the combinations apply, the value will be, of course, the number itself.

14
00:00:53,520 --> 00:00:57,830
Now the code from the end of the last video appears below so that you can check your results.

15
00:00:57,870 --> 00:00:59,250
So that's Challenge 1.

16
00:00:59,410 --> 00:01:02,760
Now let's actually have a look at Challenge 2. And I've got that file

17
00:01:02,760 --> 00:01:05,099
open been here, compchallenge2.py.

18
00:01:05,280 --> 00:01:10,680
So the challenge there is to create a comprehension that returns a list of all the locations that have

19
00:01:10,680 --> 00:01:12,240
an exit to the forest.

20
00:01:12,240 --> 00:01:14,760
Now the list should contain the description of each location,

21
00:01:14,760 --> 00:01:21,320
if it's possible to get to the forest from there. Now the forest is location 5 in the locations dictionary,

22
00:01:21,340 --> 00:01:23,250
and of course we've worked on that previously.

23
00:01:23,280 --> 00:01:27,440
Now the exits for each location, well they're represented by the exits dictionary.

24
00:01:27,620 --> 00:01:32,520
And remember that a dictionary has a dot values method to return a list of the values.

25
00:01:32,520 --> 00:01:37,350
Now the forest can be reached from the road and the hill, so those should be the descriptions that appear

26
00:01:37,350 --> 00:01:38,240
in your list.

27
00:01:38,260 --> 00:01:43,950
Now test your program with different destinations, such as one for the road, to make sure it works.

28
00:01:43,950 --> 00:01:45,390
Now once it's working,

29
00:01:45,390 --> 00:01:49,610
modify the program so that the comprehension returns a list of tuples.

30
00:01:49,700 --> 00:01:55,350
Now each tuple consists of the location number and the description, and finally wrap your comprehension

31
00:01:55,410 --> 00:02:01,200
in a for loop, and print the lists of all the locations that lead to each of the other locations in

32
00:02:01,200 --> 00:02:01,810
turn.

33
00:02:02,040 --> 00:02:09,030
So in other words, use a for loop to run the comprehension for each of the keys in the locations dictionary.

34
00:02:09,030 --> 00:02:14,360
So that's Challenge 2, and the text for these will be in the resources section of each video,

35
00:02:14,450 --> 00:02:18,090
so you can easily spot those. Now Challenge 3,

36
00:02:18,280 --> 00:02:22,110
now I can't show you any code for this because the code's going to be based on what you've done in Challenge

37
00:02:22,110 --> 00:02:24,090
2. So for this one,

38
00:02:24,180 --> 00:02:27,750
you want to convert all comprehensions in the previous challenge,

39
00:02:27,840 --> 00:02:29,730
that's challenge 2, to for loops.

40
00:02:29,970 --> 00:02:33,210
So we start off by creating a list comprehension for a for loop.

41
00:02:33,420 --> 00:02:35,020
This challenge is to go the other way,

42
00:02:35,250 --> 00:02:40,470
converting each of the comprehensions in the previous challenge into a for loop that produces the same

43
00:02:40,470 --> 00:02:41,620
result.

44
00:02:41,630 --> 00:02:46,350
Alright, so that's the three challenges. I'm going to go over the solutions to all three in the next

45
00:02:46,350 --> 00:02:51,740
video, and the code for the two of the files will be available in the resources section of this video.

46
00:02:51,740 --> 00:02:55,540
And of course challenge 3 is reliant on your Challenge 2 solution,

47
00:02:55,640 --> 00:03:00,010
so that hasn't got any starting code other than your Challenge 2 solution.

48
00:03:00,330 --> 00:03:02,720
So with that said, I'll see you in the next video.

