Python 3.3 : Rescue Buoy : Function
We are going to continue our program with the help buoy concerning the functions here it is necessary to ask ourselves several questions to know at which moment uses the function? at which moment we use the keyword return? and to what serves the function? when we look at our program, we can see and here we have the definition of the function which is materialized by the keyword def and then we have the call of the function, don't forget the parenthesis which are very necessary if for example I delete this and I run my program you will see that there is an error at this level, I am told about the function ask age and was not normally return the value of this function was not returned is because of the parentheses we put back our brackets and then we can't get the values that are here because of this function because this function if normally should return a result here age_init it should be noted that a function is like a black drink that allows you to do several things at once with just a few lines of code. For example if I copy this here and I put here for example it's not the same as when I put in the function there is a difference already that we see that at this level, there is a problem the return if is not normally in its place if I look carefully at my code the variable age init is actually the result of the function that is assigned to the value age if I change you for example and I do something like this inside I put age init you see that there is an error, there is an error simply because the age si is defined rather in the function therefore it is a local value the age that here is a global value of which these executable especially the code now this is just executable in the function that's why we try to name it in a different way and it is also necessary to structure its code well to put the tabulations if for example in the function ask age if, I know a tabulation so that the while loop will take the keyword return, I will make a tabulation and that I execute my code there is no difference between the two, it returns well result there is no difference but if I put instead the return in except You will see that there is a difference it makes tabulation, I throw my code there is an error because the value entered not user did not recover it turns over and inside except if I restart my program and that I but rather a value which has an error one will restart like this I put Titi after I put anything you see it is well returned at the level of except that to recover the print with the error, is displayed normally and it returns a value of 0 to the user, so we call you Titi and you have 0 years, next year you will have 1 year, so think to indent your code well to put the return when it is necessary, we often have functions that do not return a value, and functions that return values like this function. This function returns a precise result which is the initial age and will be stored in age. So generally speaking, functions are used to simplify the code and prevent repetition, Well that's all for this video, we'll see you soon for another one on the exercise on function ask the name.