Hi again, you should be able to remember this program which we built in one of
the previous lectures. What this does is it has this function definition which
gets the age and then it adds 50 to the age and that returns age plus 50 here and
you ask the user to enter some input and then you pass that input to the
program and then the program produces you know the age that the user submits
plus 50. That's the idea. Let's say 40 and get 90 point. Now the user may also
want to pass 200 for example for the age and you get to 250 which is not very
realistic let's be honest and here is where you want to make your program more
intelligent here is where you use a conditional, so slowly you are seeing how
you can use features of a programming language to make some real programs this
is not the real world program because in this it's depending on the a common
line interface is not very friendly to execute programs this way, but the logic
is going towards a real world program so let's go ahead and improve the program
so that if the user submits an age of let's say more than 150 you will not
calculate 150 plus 50 instead you will you print out a message that says you
it's not possible to have this age or something like. Let's go ahead
and do that. This is a function definition. Now you shouldn't incorporate
the conditional inside the function definition. You know it's good to leave
functions simple as it is now so it gets an input and it calculates the output,
so you can incorporate the conditional when you call the function in here, so
let me delete that. The function of you and then you asked for input, and then
instead of calling the function right away you first want to check, to evaluate
the input that the user submits, so let's check that. If age is less than 150 that
is the time when you want to call the function age, so you're passing age in
there, else, so if it's not less than 150 you want to print out the message saying
something like how is that possible. So let me pass the print here as well, so
we're printing the output. And let me execute. I expect to get an error
here, but it's good to take things step by step. Enter your age. Let me enter 99
first and yeah you get an error which says type error. Unorderable types string
is less than integer, so basically Python cannot compare a string object
with an integer and this is in line 7 which is this one here so this is a string.
This is an integer and the reason is that you know as I have mentioned before Python loads
user input as strings, so age will be a string data type so you want to convert
that into an integer or float. It's good to convert it to a float. You can either
do that here or you can do it here. I'll do it here like that, but if you do it
there then you can remove that from there, so don't need to convert age
twice to a float, you know you can convert it at the source in here and then you
can use it directly everywhere in your code so this is good when you're using
this input more than once in your code. You can covert it directly
here. Float, save, try again and you get the output so 99 plus 50, 149, and let
me try again to enter 151 which is above the threshold.
You get how is it possible? That the idea. This is how you use
conditional blocks. If your imagination is good then you can go ahead and improve
this program even further, so there's always something to improve. Give it
a try and I'll talk to you later. Thanks.