All language subtitles for 10- Exercise 1- Max of Two Numbers

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Alright here's an exercise for you

I want you to write a function that takes two numbers and returns

the maximum of the two. Call that function, give a different

argument, and make sure it's working properly. So pause the video,

do this exercise, and when you're done come back and continue watching.

I'm going to start by defining a function, call it max,

here we need two parameters, we can call them number 1, and

number2, or we can use shorter names like

a, and b, now earlier I told you not to use

mysterious variable names like a and b, but in this particular case

doesn't really matter, because a and b are kind of self explanatory, so we are not

dealing with a complex logic, we don't have to guess what a and b

are as you will see in a second. So in this function,

you want to have some logic, we want to compare the value of a with b, so we're

gonna use an if statement, so if

a is greater than b, we want to return

a. else you want to return b.

That's the simplest implementation, it's not the best way, we're going to optimize

this step by step, but before going any further, let's make sure

that this function actually works. So I'm going to declare

a variable called number and set it to max of

1 and 2. Now let's display number on the

console. Save the changes, so

max is 2, so if the second argument is greater,

our function works, what if the first argument is greater, so

let's change 1 to 3, save, now we see 3,

perfect, what if both arguments are equal,

once again, save the changes, we still see 3, perfect,

now before going any further, did you notice how I called this function

with different arguments, I called it with different test cases.

First I assume that the second argument is greater,

then I assume if the first argument is greater, and finally I assume

that both arguments are equal. So when writing code, when writing functions,

you should test your functions with different possible values, okay?

Now, let's get back to this max function and clean up this code.

But first thing I want to improve here is to remove

this else keyword. Why? Because of 8 is greater

than b, we're going to return a, so we'll jump out of this function.

So none of the code after line 6 will be executed, in fact,

it will never get to this point, so we don't really need the else

keyword. Okay? So if a is greater than b, we'll

return a, otherwise we'll return b. So this is a

cleaner implementation. But hey we can make this even cleaner. So earlier

we learned about the conditional operator. Remember this?

So we add a condition in parenthesis.

Question mark, if this question evaluates to true,

we use 1 value, otherwise we use the other value.

We can rewrite these two lines, using our conditional operator

so what is the condition here? If a is greater than b.

If this condition is true, we want to return a,

otherwise we want to return b. All we need here is

a return statement and terminate this with a semi colon.

So, this line is exactly equivalent to these two lines.

Now, save the changes,

both arguments are equal, you get 3, so far so good,

let's try another test case. I'm going to make the first argument

larger, let's say 5, we get 5,

now let's make the second argument larger, 10, beautiful.

So our function is working.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.