1 00:00:00,450 --> 00:00:04,500 All right guys, it's time for your final coding exercise. 2 00:00:04,950 --> 00:00:08,010 So click on day 1.4 variables. 3 00:00:09,690 --> 00:00:14,690 Now the aim of the game is to switch the values of these two variables around. 4 00:00:18,630 --> 00:00:21,540 So if we go ahead and run our code as it is, 5 00:00:21,690 --> 00:00:25,320 it's going to ask us for a value of a. Let's call it five. 6 00:00:25,920 --> 00:00:30,330 And then it's going to ask us a value for b. Let's call that a hundred. 7 00:00:30,870 --> 00:00:32,520 And then when I hit enter, 8 00:00:32,670 --> 00:00:37,670 what you want the code to do is to go ahead and print a equals 100 and b equals 9 00:00:40,680 --> 00:00:41,513 five. 10 00:00:41,670 --> 00:00:46,620 So, basically switch those values around. And you're going to have to write your 11 00:00:46,620 --> 00:00:49,680 code in here. And it's really, 12 00:00:49,680 --> 00:00:54,680 really important that you don't change any of the code here or the code here. 13 00:00:55,770 --> 00:01:00,770 Now it's easy enough to simply just write print a equals b and b equals a. 14 00:01:04,500 --> 00:01:08,730 But this doesn't test you on anything. This is not the solution. 15 00:01:08,730 --> 00:01:13,200 This is wrong. Don't change the code here, don't change the code here. 16 00:01:13,230 --> 00:01:14,040 Instead, all 17 00:01:14,040 --> 00:01:19,040 you have are these lines where you can write as much code or as little code as 18 00:01:19,320 --> 00:01:23,340 you need to achieve this end. And when you achieve it, 19 00:01:23,370 --> 00:01:24,990 it should look something like this. 20 00:01:25,020 --> 00:01:29,430 You type a value for a, you type a value for b. And when you hit enter, 21 00:01:29,670 --> 00:01:30,750 they get printed out, 22 00:01:30,750 --> 00:01:34,950 but switched around. Have a think about how variables work, 23 00:01:35,250 --> 00:01:39,210 how they store data. And if you get really stuck, 24 00:01:39,240 --> 00:01:43,440 imagine that you have two cups; one holds a cup of milk, one 25 00:01:43,440 --> 00:01:44,610 holds a cup of coffee, 26 00:01:44,880 --> 00:01:49,290 and you wanna switch the contents of the cup around. How would you do that in 27 00:01:49,290 --> 00:01:53,460 real life? And then try and see if you can apply that logic to the code. 28 00:01:54,090 --> 00:01:56,130 Pause the video now and give this a go. 29 00:02:00,930 --> 00:02:04,050 All right. So I hope you didn't cheat 30 00:02:04,170 --> 00:02:08,340 and instead you actually had a think about this problem. If you got stuck, 31 00:02:08,370 --> 00:02:09,330 remember how I said 32 00:02:09,360 --> 00:02:13,170 if you have a cup of coffee and you have a cup of milk and you wanna switch the 33 00:02:13,170 --> 00:02:18,090 contents of the cups around, how would you do this in real life? Well, 34 00:02:18,120 --> 00:02:21,570 you would probably get a third cup, right? 35 00:02:22,320 --> 00:02:25,410 And then you'd be able to shift the contents around. 36 00:02:25,920 --> 00:02:28,980 So that's exactly what we're going to do with our code as well. 37 00:02:29,880 --> 00:02:34,880 We can create a new variable called c and we can set that to equal the value that's 38 00:02:36,510 --> 00:02:39,960 stored inside a. And then later on, 39 00:02:40,170 --> 00:02:45,170 we can get the variable a to store the value that's currently inside b. 40 00:02:46,590 --> 00:02:47,700 And finally, 41 00:02:47,730 --> 00:02:52,730 we're now ready to get b to store the value that was previously inside a, 42 00:02:53,640 --> 00:02:58,640 which is now contained inside the variable c. These three lines achieve this 43 00:02:59,530 --> 00:03:01,360 little switch rule that we've got here. 44 00:03:01,990 --> 00:03:06,610 And this is one of the most common Programming interview questions that you will 45 00:03:06,610 --> 00:03:09,610 come across. And the code is super simple, 46 00:03:10,060 --> 00:03:13,630 but what you have to apply here is some logic. 47 00:03:13,810 --> 00:03:16,030 And I usually think about real life examples 48 00:03:16,030 --> 00:03:18,850 like the cups and I hope that helped you as well. 49 00:03:19,390 --> 00:03:21,790 If this was at all confusing, 50 00:03:22,150 --> 00:03:25,240 then have a go at trying this out in Thonny. 51 00:03:25,840 --> 00:03:28,570 But if you got it right, then congratulations. 52 00:03:28,570 --> 00:03:30,910 This was actually quite a hard challenge. 53 00:03:31,150 --> 00:03:35,440 You had to think about a lot of things and think outside the box as well. 54 00:03:35,890 --> 00:03:38,050 So give yourself a pat on the back if you've got it right. 55 00:03:38,470 --> 00:03:39,640 If you didn't get it right, 56 00:03:39,640 --> 00:03:44,640 then I really recommend to put this code inside Thonny and see how it's being 57 00:03:45,430 --> 00:03:47,110 moved around so that you really, 58 00:03:47,110 --> 00:03:49,510 really understand what's going on behind the scenes. 59 00:03:50,440 --> 00:03:55,150 And then you can move on to the next lesson where we're going to talk about some 60 00:03:55,150 --> 00:03:59,080 of the rules around naming variables. For all of that 61 00:03:59,230 --> 00:04:00,400 and more, I'll see you there.