2022-10-11 19:27:51 +00:00
|
|
|
# This function computes the body mass index (BMI),
|
|
|
|
# given the height (in meter) and weight (in kg) of a person.
|
|
|
|
def bodyMassIndex(height, weight):
|
|
|
|
# Complete the function definition...
|
2023-05-16 20:14:36 +00:00
|
|
|
bmi = weight / height**2
|
2022-10-11 19:27:51 +00:00
|
|
|
return bmi
|
|
|
|
|
|
|
|
|
|
|
|
# This function returns the BMI category acording to this table:
|
|
|
|
# BMI: <18.5 [18.5, 25[ [25, 30[ 30 or greater
|
|
|
|
# Category: Underweight Normal weight Overweight Obesity
|
|
|
|
def bmiCategory(bmi):
|
2023-05-16 20:14:36 +00:00
|
|
|
assert bmi>0
|
2022-10-11 19:27:51 +00:00
|
|
|
# Complete the function definition...
|
|
|
|
if bmi < 18.5:
|
|
|
|
return 'Underweight'
|
|
|
|
elif bmi < 25:
|
|
|
|
return 'Normal weight'
|
|
|
|
elif bmi < 30:
|
|
|
|
return 'Overweight'
|
|
|
|
else:
|
|
|
|
return 'Obesity'
|
|
|
|
|
|
|
|
|
|
|
|
# This is the main function
|
|
|
|
def main():
|
|
|
|
print("Índice de Massa Corporal")
|
2023-05-16 20:14:36 +00:00
|
|
|
|
2022-10-11 19:27:51 +00:00
|
|
|
altura = float(input("Altura (m)? "))
|
|
|
|
if altura < 0:
|
|
|
|
print("ERRO: altura inválida!")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
peso = float(input("Peso (kg)? "))
|
|
|
|
if peso < 0:
|
|
|
|
print("ERRO: peso inválido!")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# Complete the function calls...
|
|
|
|
imc = bodyMassIndex(altura, peso)
|
|
|
|
cat = bmiCategory(imc)
|
|
|
|
|
|
|
|
print("BMI: {:.2f} kg/m2".format(imc))
|
|
|
|
print("BMI category:", cat)
|
|
|
|
|
|
|
|
|
|
|
|
# Program starts executing here
|
2022-10-18 17:18:56 +00:00
|
|
|
if __name__ == "__main__":
|
2023-05-16 20:14:36 +00:00
|
|
|
main()
|