1
00:00:01,560 --> 00:00:02,550
In this exercise,

2
00:00:02,550 --> 00:00:06,300
the goal is to use what you've learned about variables

3
00:00:06,300 --> 00:00:11,300
to figure out how to switch the value in two variables.

4
00:00:12,540 --> 00:00:16,020
The idea here is we've got two values

5
00:00:16,020 --> 00:00:20,880
that is put into the Input pane on lines one and two.

6
00:00:20,880 --> 00:00:24,480
So the first one, in this case 29,

7
00:00:24,480 --> 00:00:29,480
is going to be substituted into the variable "a" on line two.

8
00:00:30,720 --> 00:00:34,290
The second one, 41, is going to be set equal

9
00:00:34,290 --> 00:00:37,053
to the variable "b" on line three.

10
00:00:37,890 --> 00:00:42,810
Your goal is to write some code between lines seven and 10

11
00:00:42,810 --> 00:00:45,690
that can switch those values around

12
00:00:45,690 --> 00:00:49,283
so that when the print statement runs on lines 12 and 13,

13
00:00:49,283 --> 00:00:54,283
that it will print a as equal to the value of 41,

14
00:00:54,750 --> 00:00:57,270
which used to be stored in b 

15
00:00:57,270 --> 00:01:02,070
and line 15 will print b  and then colon

16
00:01:02,070 --> 00:01:04,440
and then the value 29,

17
00:01:04,440 --> 00:01:08,880
which used to be stored in the variable b.

18
00:01:08,880 --> 00:01:11,850
It is just a switcheroo and you're going have to think

19
00:01:11,850 --> 00:01:15,720
about how to do this using what you know about variables.

20
00:01:15,720 --> 00:01:18,813
There's many ways to solve this, but give it a go now.

21
00:01:24,600 --> 00:01:28,740
All right, so the solution only takes three lines of code

22
00:01:28,740 --> 00:01:31,653
and I'm going to run through them each one-by-one.

23
00:01:32,550 --> 00:01:36,150
The first step was to create a third variable

24
00:01:36,150 --> 00:01:39,510
and this is key to solving this exercise

25
00:01:39,510 --> 00:01:43,170
because we need some temporary store.

26
00:01:43,170 --> 00:01:46,920
If we set "c" equal to the value of a,

27
00:01:46,920 --> 00:01:49,680
right now using the example input,

28
00:01:49,680 --> 00:01:53,010
c is equal to the word assembly.

29
00:01:53,010 --> 00:01:58,010
Next, we set a equal to the value of b,

30
00:01:58,110 --> 00:02:02,250
so a is now equal to "Basic".

31
00:02:02,250 --> 00:02:06,750
Finally, we set b equal to the value of c

32
00:02:06,750 --> 00:02:09,660
so that we take that temporary variable,

33
00:02:09,660 --> 00:02:14,660
grab the value inside and put it into the variable b.

34
00:02:15,060 --> 00:02:19,320
So now we've switched the values in a and b around

35
00:02:19,320 --> 00:02:24,150
and we have no longer any use for the value inside c.

36
00:02:24,150 --> 00:02:26,850
But at this point, the switcheroo is complete

37
00:02:26,850 --> 00:02:29,340
and when we print out a and b,

38
00:02:29,340 --> 00:02:33,990
they will show the opposite of what they use to hold.

39
00:02:33,990 --> 00:02:38,400
So now, given the current example Input, Assembly and Basic,

40
00:02:38,400 --> 00:02:42,480
we will end up with Basic Assembly being outputted,

41
00:02:42,480 --> 00:02:44,223
switching the values around.

42
00:02:45,090 --> 00:02:47,250
So if you needed to make any changes to your code,

43
00:02:47,250 --> 00:02:49,620
feel free to go back to the previous slide,

44
00:02:49,620 --> 00:02:51,960
but have a think about why this works

45
00:02:51,960 --> 00:02:54,510
and how creating variables allow us

46
00:02:54,510 --> 00:02:57,330
to store values inside them,

47
00:02:57,330 --> 00:02:59,733
just like boxes when you're moving.

