Example #1
0
 def run(self):
     data = self.__get_data()
     bmi = BMI(data['weight'], data['height'])
     calculated_bmi = bmi.get_bmi()
     self.__print_line()
     print('BMI: %0.2f' % calculated_bmi)
     self.__print_line()
     bmi_norm = bmi.norm()
     if bmi_norm == -1:
         print('You are underweight!')
         self.__print_line()
         correct_weight = bmi.get_correct_weight()
         if correct_weight is not False:
             print('Your correct weight should be: %0.0f' % correct_weight)
             self.__print_line()
             print('To increase the weight You need to eat[kg]:')
             self.__print_line()
             self.__to_increase_weight(correct_weight - data['weight'])
     elif bmi_norm == 0:
         print('You have a healthy weight!')
         self.__print_line()
     elif bmi_norm == 1:
         print('You are overweight!')
         self.__print_line()
         correct_weight = bmi.get_correct_weight()
         if correct_weight is not False:
             print('Your correct weight should be: %0.0f' % correct_weight)
             self.__print_line()
             print('To reduce the weight You need exercise[h]:')
             self.__print_line()
             self.__to_reduce_weight(data['weight'] - correct_weight)
 def test_bmi_no_height_no_weight(self):
     human_bmi = BMI()
     self.assertEqual(human_bmi.get_bmi(), False)
 def test_get_bmi_overrweight(self):
     human_bmi = BMI(weight=86, height=1.55)
     self.assertEqual(human_bmi.norm(), 1)
 def test_get_bmi_norm_ok(self):
     human_bmi = BMI(weight=84, height=1.85)
     self.assertEqual(human_bmi.norm(), 0)
 def test_bmi_norm_underweight(self):
     human_bmi = BMI(weight=60, height=1.95)
     self.assertEqual(human_bmi.norm(), -1)
 def test_get_bmi(self):
     human_bmi = BMI(weight=86, height=1.85)
     self.assertEqual(human_bmi.get_bmi(), 25.127830533235937)
 def test_bmi_no_weight(self):
     cat_bmi = BMI(height=1.85)
     self.assertEqual(cat_bmi.get_bmi(), False)
Example #8
0
    def calculate_bmi(self, cb_type, weight_entry, height_entry, bmi_label,
                      norm_label):
        """Calculate BMI."""
        weight = weight_entry.get()
        height = height_entry.get()

        weight = weight.replace(',', '.')
        height = height.replace(',', '.')

        try:
            try:
                weight = float(weight)
            except ValueError:
                raise Exception('Weight must be an number value!')
            if weight <= 0:
                raise Exception('Weight must be bigger then 0!')
            try:
                height = float(height)
            except ValueError:
                raise Exception('Height must be an number value!')
            if height <= 0:
                raise Exception('Height must be bigger then 0!')
            an_type = cb_type.get()
            if an_type == 'HUMAN':
                bmi_label.configure(text=an_type)
                bmi = BMI(weight, height)
                calculated_bmi = str(round(bmi.get_bmi(), 2))
                bmi_label.configure(text=calculated_bmi)
                bmi_norm = bmi.norm()
                if bmi_norm == -1:
                    norm_label.configure(text='You are underweight!',
                                         bg='#ffcc00')
                elif bmi_norm == 0:
                    norm_label.configure(text='You have a healthy weight!',
                                         bg='#00cc00')
                elif bmi_norm == 1:
                    norm_label.configure(text='You are overweight!',
                                         bg='#e60000')
            elif an_type == 'DOG':
                bmi = DogBMI(weight, height)
                calculated_bmi = str(round(bmi.get_bmi(), 2))
                bmi_label.configure(text=calculated_bmi)
                bmi_norm = bmi.norm()
                if bmi_norm == -1:
                    norm_label.configure(text='You are underweight!',
                                         bg='#ffcc00')
                elif bmi_norm == 0:
                    norm_label.configure(text='You have a healthy weight!',
                                         bg='#00cc00')
                elif bmi_norm == 1:
                    norm_label.configure(text='You are overweight!',
                                         bg='#e60000')
            elif an_type == 'CAT':
                bmi = CatBMI(weight, height)
                calculated_bmi = str(round(bmi.get_bmi(), 2))
                bmi_label.configure(text=calculated_bmi)
                bmi_norm = bmi.norm()
                if bmi_norm == -1:
                    norm_label.configure(text='You are underweight!',
                                         bg='#ffcc00')
                elif bmi_norm == 0:
                    norm_label.configure(text='You have a healthy weight!',
                                         bg='#00cc00')
                elif bmi_norm == 1:
                    norm_label.configure(text='You are overweight!',
                                         bg='#e60000')
        except Exception as e:
            messagebox.showerror('Error', e)