daily pastebin goal
67%
SHARE
TWEET

NPTO

a guest Mar 13th, 2018 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ====== CATEGORIES FOR BMI =======
  2. # === DO NOT CHANGE THIS CODE V ===
  3. # first value - from value (if None, then should be treated as 0)
  4. # second value - to value (if None, then should be treted as 100)
  5. # third value - category label
  6. bmi_categories_threshold = [
  7.     (None, 15, "Very severely underweight"),
  8.     (15, 16, "Severely underweight"),
  9.     (16, 18.5, "Underweight"),
  10.     (18.5, 25, "Normal (healthy weight)"),
  11.     (25, 30, "Overweight"),
  12.     (30, 35, "Moderately obese"),
  13.     (35, 40, "Severely obese"),
  14.     (40, None, "Very severely obese")
  15. ]
  16. # === DO NOT CHANGE THIS CODE ^ ===
  17.  
  18. # function for calculating BMI value
  19. def calculate_bmi(w, h):
  20.     """
  21.    Parameters
  22.    ----------
  23.    w : float
  24.        Weight of the patient (in kg)
  25.    h : str
  26.        Height of the patient (in meters)
  27.  
  28.    Returns
  29.    -------
  30.    bmi : float
  31.        Calculated value for BMI based on equation: weight / height ^2
  32.    """
  33.     return w / (h ** 2)
  34.  
  35. # function for getting label based on bmi value
  36. def get_bmi_category(bmi_value):
  37.     """
  38.    Parameters
  39.    ----------
  40.    bmi_value : float
  41.        Calculated value for BMI
  42.  
  43.    Returns
  44.    -------
  45.    output_labels : list
  46.        List with string labels for BMI category for input value
  47.    """
  48.     output_labels = []
  49.  
  50.     for value_from_, value_to_, label in bmi_categories_threshold:
  51.         if value_from_ is None:
  52.             value_from_ = 0
  53.         else:
  54.             value_from_ = value_from_
  55.        
  56.         if value_to_ is None:
  57.             value_to_ = 100  # example maximum value
  58.         else:
  59.             value_to_ = value_to_
  60.  
  61.         if bmi_value >= value_from_ and bmi_value <= value_to_:
  62.             output_labels.append(label)
  63.            
  64.  
  65.     return output_labels
  66.  
  67. # patients to test
  68. # first value name, second is weight, third is height
  69. example_patients = [
  70.     ("Jan Szpan", 70, 1.8),
  71.     ("Jan Kowalski", 80, 1.9),
  72.     ("Jan Janowicz", 150, 1.7),
  73.     ("Arnold Boczek", 120, 2)
  74. ]
  75.  
  76. # function for preparing results for patients
  77. def get_bmi_category_for_patients(patients):
  78.     """
  79.    Parameters
  80.    ----------
  81.    patients : list
  82.        List of patients in the following format for each list item:
  83.        (string_value_for_name, weight, height)
  84.  
  85.    Returns
  86.    -------
  87.    results : list
  88.        List with results for each list item:
  89.        (bmi_value, bmi_category)
  90.    """
  91.     results = []
  92.  
  93.     for patient in patients:
  94.         bmi_value = round(calculate_bmi(patient[1], patient[2]), 2)
  95.         bmi_category = str(get_bmi_category(bmi_value))
  96.         results.append((bmi_value, bmi_category))
  97.         print(">> Patient", patient[0])
  98.         print("\tBMI value:", bmi_value, "\tCategory:", bmi_category)
  99.  
  100.     return results
  101.  
  102. results = get_bmi_category_for_patients(example_patients)
  103.  
  104. # ====== TESTING PROCEDURE ========
  105. # === DO NOT CHANGE THIS CODE V ===
  106. # expected results
  107. expected_results = [
  108.     (21.6, "['Normal (healthy weight)']"),
  109.     (22.16, "['Normal (healthy weight)']"),
  110.     (51.9, "['Very severely obese']"),
  111.     (30, "['Overweight', 'Moderately obese']")
  112. ]
  113.  
  114. # comparing expected results and results acquired
  115. for index, (expected_result, result) in enumerate(zip(expected_results, results)):
  116.     assert result[0] == expected_result[0]
  117.     assert result[1] == expected_result[1]
  118. # === DO NOT CHANGE THIS CODE ^ ===
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top