1
00:00:00,180 --> 00:00:01,650
In this exercise, you're going

2
00:00:01,650 --> 00:00:04,050
to be creating a function

3
00:00:04,050 --> 00:00:09,050
that adds countries that you've visited into a Travel Log.

4
00:00:09,330 --> 00:00:10,960
Take a look in the starting code,

5
00:00:12,080 --> 00:00:14,820
there is a list of dictionaries called travel_log

6
00:00:14,820 --> 00:00:17,760
and it contains keys and values such

7
00:00:17,760 --> 00:00:20,850
as the country that was visited, the number of visits made

8
00:00:20,850 --> 00:00:24,480
and the cities that have been visited in that country.

9
00:00:24,480 --> 00:00:26,280
Now, the goal for you is

10
00:00:26,280 --> 00:00:29,394
without modifying this travel_ log directly

11
00:00:29,394 --> 00:00:33,810
you should create a function called add_new_country

12
00:00:33,810 --> 00:00:35,400
which takes three inputs

13
00:00:35,400 --> 00:00:38,229
the name of the country, the number of visits

14
00:00:38,229 --> 00:00:43,024
and the cities that have been visited in a list.

15
00:00:43,024 --> 00:00:45,240
Take a look in the Description box,

16
00:00:45,240 --> 00:00:46,920
look at the Example Input

17
00:00:46,920 --> 00:00:50,269
and what the Expected Output should look like

18
00:00:50,269 --> 00:00:53,055
and try to create your function.

19
00:00:53,055 --> 00:00:56,880
Remember, you shouldn't need to modify the travel_

20
00:00:56,880 --> 00:00:59,250
log directly, and instead

21
00:00:59,250 --> 00:01:02,940
you should write the function that achieves this purpose

22
00:01:02,940 --> 00:01:05,099
because otherwise when you hit Submit

23
00:01:05,099 --> 00:01:07,770
your code is not going to pass the test.

24
00:01:07,770 --> 00:01:10,470
Look at the instructions carefully and give this a go.

25
00:01:17,790 --> 00:01:20,130
All right hopefully you managed to complete this

26
00:01:20,130 --> 00:01:23,220
and you want to check the solution together with me.

27
00:01:23,220 --> 00:01:27,001
If you didn't manage to complete it and you want to get a hint

28
00:01:27,001 --> 00:01:29,490
or see how I did it, then feel free to follow along

29
00:01:29,490 --> 00:01:32,220
and we can review the solution together.

30
00:01:32,220 --> 00:01:35,010
Now, the first step is to create our function

31
00:01:35,010 --> 00:01:37,863
which is called add_new_country.

32
00:01:38,850 --> 00:01:41,220
Next, we provide the three inputs

33
00:01:41,220 --> 00:01:46,050
to this function that's already been defined on line 24,

34
00:01:46,050 --> 00:01:48,390
that's the name of the country,

35
00:01:48,390 --> 00:01:50,884
the times that have been visited,

36
00:01:50,884 --> 00:01:53,940
and the cities that have been visited.

37
00:01:53,940 --> 00:01:57,660
Now notice I've named the inputs in the function

38
00:01:57,660 --> 00:02:01,950
on line 17 different from what's on line 24

39
00:02:01,950 --> 00:02:04,050
just so that you can tell the difference when

40
00:02:04,050 --> 00:02:06,302
I use it in the function.

41
00:02:06,302 --> 00:02:07,530
In reality

42
00:02:07,530 --> 00:02:10,380
you can call your inputs whatever it is you like,

43
00:02:10,380 --> 00:02:12,093
as long as it works, it's fine.

44
00:02:13,200 --> 00:02:15,555
Now, the next thing we need to do is to create

45
00:02:15,555 --> 00:02:19,592
a new dictionary, which I've called new_country

46
00:02:19,592 --> 00:02:24,592
and the first thing we do is we provide a key and value pair

47
00:02:25,680 --> 00:02:27,827
and put it into this new dictionary.

48
00:02:27,827 --> 00:02:32,490
We can write new_country[ ], inside the square

49
00:02:32,490 --> 00:02:35,790
brackets the key, which is country, and then

50
00:02:35,790 --> 00:02:39,030
we can set it equal to the value, which is the first input

51
00:02:39,030 --> 00:02:42,694
on line 17, the name of the country that has been visited.

52
00:02:42,694 --> 00:02:46,290
Next, we do the same thing with the other two inputs

53
00:02:46,290 --> 00:02:50,280
the number of visits and the cities that have been visited.

54
00:02:50,280 --> 00:02:53,700
So we're just passing the data through the function.

55
00:02:53,700 --> 00:02:54,533
The data comes

56
00:02:54,533 --> 00:02:59,100
into the function, and we can grab it by the names

57
00:02:59,100 --> 00:03:00,360
through the names of the input

58
00:03:00,360 --> 00:03:03,840
on line 17, and we insert them one by one into

59
00:03:03,840 --> 00:03:07,254
this new dictionary that we've created, called new_country.

60
00:03:07,254 --> 00:03:09,690
Finally, all we have to do to add it

61
00:03:09,690 --> 00:03:14,690
to our list is to use the append() method, so we grab hold

62
00:03:14,730 --> 00:03:18,870
of our travel_log list, write .append, and then

63
00:03:18,870 --> 00:03:23,280
inside the parentheses we can add what we want to append

64
00:03:23,280 --> 00:03:26,910
or what we want to add to the end of that list.

65
00:03:26,910 --> 00:03:29,700
And it is of course our new entry

66
00:03:29,700 --> 00:03:31,500
that new dictionary that we created

67
00:03:31,500 --> 00:03:35,070
which is called new_country, and that's all there is to it.

68
00:03:35,070 --> 00:03:37,540
We managed to grab hold of the inputs,

69
00:03:38,834 --> 00:03:41,580
put it into a new dictionary by key and value pairs

70
00:03:41,580 --> 00:03:46,110
and then insert it into the list of our travel_log.

71
00:03:46,110 --> 00:03:48,120
If you need to make any adjustments to your code

72
00:03:48,120 --> 00:03:49,370
go ahead and do that now.

