All language subtitles for 8. Sum of All Even Numbers - Solution

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
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
fa Persian
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

Oh, right.

So I hope you tried to solve this exercise on your own and you came to some conclusion.

So first thing that I would like us to do is just let's not delete it.

Let's basically copied and pasted right here, be it, OK?

So let's say some even numbers.

OK, some even numbers.

So this recursive function is basically going to read and input from the user on every recursive call.

And then what we are going to do is to check if the base condition is satisfied.

If yes, we are going to return again.

Zero.

Right.

Why again are we returning to zero?

That's very simple, because if if we know that we insert minus one, that's the stopping condition.

And the contribution of this final result to the sum of all the even numbers in a sequence is basically

zero.

That's why we return here.

Zero, although a lot of exercises you will see pretty much in this sequence, this exercise is you

are going to see a lot of times a return result of zero.

That's in the base case.

That's not something that is mandatory or that will always occur.

OK, we can have a lot of also a lot of other examples where the result here of the return value will

not be zero.

OK, but maybe we'll we will do also some exercises just like that.

So.

All right, with that being said, let's move on to the important part, because everything up until

now was pretty much the same.

We just modified the function name in the reading of the input was the same and the input from the user,

the stubborn condition was also the same.

And now let us talk about the recursive calls.

Probably here we will have something to modify, something to edit to satisfy the solution for the some

of even numbers.

OK, so recursive calls.

If input user modula two equals to zero, then it's definitely an even number and we would like to do

so.

Previously we done something like this.

We did return one because that was the contribution of this given function.

Call to the count that a total count that we wanted to find out.

And now we don't want to find just the count of the total amount of even numbers we want to find there

sum and the contribution of these function call of this specific function called to the final sum of

all the even numbers in this sequence is basically just to modify this value.

This one with what value?

What do you think should be placed here?

OK, what do you think?

Well, the answer the answer is the input user value, because if that's an even number, then we would

like to add this even value to the final result and then to call another instance of this of this recursive

function.

So let's just modify it because we changed the names.

So if the input is an even number, then return this even number plus the result of the next function

call the next recursive call.

OK, and if that's not the case, we are going basically to return simply to call another recursive

instance of this function.

So I hope that's clear.

Guys, you understand what we are doing.

OK.

And of course, you can again draw everything and all of this solution once again to make sure you understand

everything correctly.

And actually, to be honest, I'm going to do it right away with you, because I think that's a good

thing to help you understand.

So that's our example, one, three, four, six.

OK, so that's the time when we call the first instance of the function, it will be some even let's

call it AC and we are calling this function and we receive from the user the value of one.

OK, and if that's the right value of one, we check this condition is false.

Then we return, we execute the 40 second line and we return the same function.

So we want here to return the result.

That is still unknown.

Right, because the result here is the result of these other function calls.

So this are another function call we are going to call it.

And here we are going to receive another input.

It will be three and we are going to return the result of something that we still don't know, because

that's the result of another function call.

So that's the other function call.

So here we get four.

OK, and if we get here four, right.

That's the example for and if we get four, we simply will check this condition and it will be true

in this case.

Then we are going to return to the input user, which is four plus, then something that we still don't

know.

So that's going to look like this four plus the result of the next function call.

So we are going to make this call again in here.

We will get six as an input.

So six and we know that's also an even number.

And we are going to return from this instance six plus something that we don't know.

Right.

We don't know this the result of this function yet, because that's another function call.

And now we are going to to get here from the user minus one.

Right, because six we've got three.

One oh we got now it's minus one.

So the user inserts minus one.

So predraft please enter a number of user specifies minus one for the final.

And then we read this value and we can see that the base condition, this stabbing condition of the

recursive calls is being satisfied.

And we know that the result return from here is zero.

So zero is returned, six plus zero is six.

So that's the result here.

Four plus six is ten and ten returned also to here.

And finally, the final result, return from all of this chain of calls for this recursive functions

is just ten.

OK, so that's basically all the function calls there that you will have to do in such an example.

OK, so make sure you understand all the concept.

When we are going to call this function into call, make the recursive calls and then when we are going

to get back once we reached some stopping condition.

Because, you know, if these two lines were not here, then this will be just an endless recursive

calls until your memory would would end in your computer.

So these are part of the stopping condition is very important also to always to formulate our correctly,

because a lot of times the problems happen also here and also in the recursive calls, of course.

But yeah, my recommendation is always do some visualization like I'm doing right here with one or two

examples.

Make sure that you reach some some base condition and make sure that the recursive calls are correct

and that and that's there.

And that's the result.

A return from every function, call from every instance is also correct.

That's very, very important.

So, yeah, guys, this is it for this video.

I think we are doing a good progress.

We are proceeding.

I don't know if we are doing, but I guess and I really hope that you are doing a good progress in this

chorus in practice by practicing these examples in these exercises.

So with that being said, my name is Vlad.

This is Alphatech.

Don't forget to leave some review, some comments and feedback to let me know if you like this material

and if you like the course so far and up until now.

So, yeah, thank you.

And we will see each other again soon enough.

Until then, have a great day.

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