Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1
All right guys, it's time for your final coding exercise.
2
So click on day 1.4 variables.
3
Now the aim of the game is to switch the values of these two variables around.
4
So if we go ahead and run our code as it is,
5
it's going to ask us for a value of a. Let's call it five.
6
And then it's going to ask us a value for b. Let's call that a hundred.
7
And then when I hit enter,
8
what you want the code to do is to go ahead and print a equals 100 and b equals
9
five.
10
So, basically switch those values around. And you're going to have to write your
11
code in here. And it's really,
12
really important that you don't change any of the code here or the code here.
13
Now it's easy enough to simply just write print a equals b and b equals a.
14
But this doesn't test you on anything. This is not the solution.
15
This is wrong. Don't change the code here, don't change the code here.
16
Instead, all
17
you have are these lines where you can write as much code or as little code as
18
you need to achieve this end. And when you achieve it,
19
it should look something like this.
20
You type a value for a, you type a value for b. And when you hit enter,
21
they get printed out,
22
but switched around. Have a think about how variables work,
23
how they store data. And if you get really stuck,
24
imagine that you have two cups; one holds a cup of milk, one
25
holds a cup of coffee,
26
and you wanna switch the contents of the cup around. How would you do that in
27
real life? And then try and see if you can apply that logic to the code.
28
Pause the video now and give this a go.
29
All right. So I hope you didn't cheat
30
and instead you actually had a think about this problem. If you got stuck,
31
remember how I said
32
if you have a cup of coffee and you have a cup of milk and you wanna switch the
33
contents of the cups around, how would you do this in real life? Well,
34
you would probably get a third cup, right?
35
And then you'd be able to shift the contents around.
36
So that's exactly what we're going to do with our code as well.
37
We can create a new variable called c and we can set that to equal the value that's
38
stored inside a. And then later on,
39
we can get the variable a to store the value that's currently inside b.
40
And finally,
41
we're now ready to get b to store the value that was previously inside a,
42
which is now contained inside the variable c. These three lines achieve this
43
little switch rule that we've got here.
44
And this is one of the most common Programming interview questions that you will
45
come across. And the code is super simple,
46
but what you have to apply here is some logic.
47
And I usually think about real life examples
48
like the cups and I hope that helped you as well.
49
If this was at all confusing,
50
then have a go at trying this out in Thonny.
51
But if you got it right, then congratulations.
52
This was actually quite a hard challenge.
53
You had to think about a lot of things and think outside the box as well.
54
So give yourself a pat on the back if you've got it right.
55
If you didn't get it right,
56
then I really recommend to put this code inside Thonny and see how it's being
57
moved around so that you really,
58
really understand what's going on behind the scenes.
59
And then you can move on to the next lesson where we're going to talk about some
60
of the rules around naming variables. For all of that
61
and more, I'll see you there.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.