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
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
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
What is going on, guys?
And in this video, we are going to solve some exercise regarding functions and we will start with a
very simple function that is called let's call this function is even so, that's the name of the function.
All right.
So that's the name of the function.
And what you have to do is to simply implement it, first of all, to define its signature, then to
write all of its implementation.
And all these function basically does is simply receiving.
OK, so this function will receive will receive an integer, some number of an integer, a type.
And this will this function will will return one if this given number is even OK.
Otherwise this function should return, these function should return.
What you need to return should return zero.
OK, so in case that it's all OK that the received number is odd, then in this case the function should
return basically zero.
Awesome.
So now take a couple of moments and think about what should be the solution for this function.
What should be should be its signature.
What type should it return?
What will be the name of the function?
OK, most of this information is already there in the instructions of this exercise.
So let us start with the the signature, OK, once you tried it on your own and the signature is going
to look like this.
So first of all, we know that the function may return either zero or one.
So we can assume, OK, in base case because we haven't studied boolean boolean types yet.
So we will assume just the usage of it.
OK, so the function will return an integer.
So either it will be zero or one and then it will specify the function name.
So it will be like is even in the function receives.
What does the function receive.
The function receives an integer.
So let's go into num.
OK, so that's the signature and that's the first step that hopefully you manage to accomplish so far.
And now we have to implement kind of the logic behind this function.
And the logic here is pretty simple.
So it goes like this.
We need to ask a simple question.
If NUM is an even number then return one, otherwise return zero.
So we should basically understand the idea in English.
But whatever language you're using, you're speaking, but here we speak in English, so now basically,
you know what you have to do in practice, but now what you have to do in coding.
So you have to specify the if and then you have to specify the number modulo two, which means that
this will represent the remainder of dividing the value of NUM by two.
If the remainder is zero, then in this case we know that number is an even number, then in this case
we will return one.
All right.
Otherwise, otherwise, ok, we can use or or else we can return to zero.
All right.
Is that clear so far.
Awesome.
So that's basically the implementation for this function.
OK, so this Ale's will be executed only if the result for this condition is false, meaning that if
you divide number by two, you will get a remainder of one, meaning it will be an odd number.
So one question.
Do you think we need this L's here?
I don't think so.
I think we can even leave it like this.
And why will it still be working?
Well, basically, if you return one, then it's kind of an end point for this function and it will
never reach this return zero.
It will only reach this line, these 13 line only if the result of this condition is false, because
if the result of this condition would happen to be true, then in this case this line would have been
executed.
And we know that we can leave it this way.
Of course, if you would have written the else, that's also fine.
I'm just showing you how we can simply like to how we can minimize a few lines of code in this case,
just one line of code.
So, yeah, guys, this is it for this video.
In the next video, I think we should practice and do the same function for is odd and we will use.
Hmm, yeah, basically, let's discuss it in the next video where we are going to solve another function.
I'll see you then.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.