why my def function doesnt work with BMI term?
Question:
I’m calculating the BMI in spanish terms but I dont getting it. Why my code doesnt work?
Looks so frustrating
>>> def IMC (estatura,peso):
... IMC = estatura / peso
... return "Tu índice de masa corporal es " + (IMC)
...
>>> estatura = 185
>>> peso = 74.60
>>> IMC
<function IMC at 0x0000019F36713E20>
>>>
Answers:
IMC
is a function, which is exactly what you see in the ouput. If you want the function to execute you have to call it and pass parameters: IMC(estatura, peso)
.
If you are familiar with functions in algebra, this is very similar. If you define f(x) = x^2
, then you write f(3)
to evaluate the function when x
is given the value of 3
. We use a similar notation in python.
The assignments estatura = 185
and peso = 74.60
create new variables that have nothing to do with the ones with the same name inside the IMC
function.
I suggest you read more about variables, functions, parameters, and scope to learn how this all works.
I’m calculating the BMI in spanish terms but I dont getting it. Why my code doesnt work?
Looks so frustrating
>>> def IMC (estatura,peso):
... IMC = estatura / peso
... return "Tu índice de masa corporal es " + (IMC)
...
>>> estatura = 185
>>> peso = 74.60
>>> IMC
<function IMC at 0x0000019F36713E20>
>>>
IMC
is a function, which is exactly what you see in the ouput. If you want the function to execute you have to call it and pass parameters: IMC(estatura, peso)
.
If you are familiar with functions in algebra, this is very similar. If you define f(x) = x^2
, then you write f(3)
to evaluate the function when x
is given the value of 3
. We use a similar notation in python.
The assignments estatura = 185
and peso = 74.60
create new variables that have nothing to do with the ones with the same name inside the IMC
function.
I suggest you read more about variables, functions, parameters, and scope to learn how this all works.