Friday, August 5, 2016

Who is going to have dessert?

In the previous post We have seen how easy is to calculate the BMI for a bunch of people when using numpy arrays. Let's go a step further and use those data.

Given a BMI numpy array, let's check which element is fit enough to stand a dessert. Basically, what we want is getting a boolean array where True means that the associated guy has a BMI less than 25. Easier to write the Python code than explain it:
   import numpy

   # ...
   # given bmis, a numpy array containing BMI for each person under surveillance

   dessert = bmis < 25
Now, if we want to check if Person One could get a slice of cake, we can just check the relative element in the numpy dessert array:
   if dessert[1]:
      print('Enjoy the dessert!')
   else:
      print('No dessert for you!')

No comments:

Post a Comment