Created
May 4, 2024 01:22
-
-
Save codermarcos/b649c3faa7b799bfde2c1f38d3c41fba to your computer and use it in GitHub Desktop.
IMC Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculatebmi(weight, height): | |
heightmeters = height / 100 | |
return weight / (heightmeters ** 2) | |
def classifybmi(bmi): | |
if bmi < 18.5: | |
return "Underweight" | |
elif 18.5 <= bmi < 25: | |
return "Normal weight" | |
elif 25 <= bmi < 30: | |
return "Overweight" | |
else: | |
return "Obese" | |
def main(): | |
age = int(input("Enter your age: ")) | |
weight = float(input("Enter your weight in kg: ")) | |
height = float(input("Enter your height in centimeters: ")) | |
bmi = calculate_bmi(weight, height) | |
classification = classify_bmi(bmi) | |
print("\n--- Result of BMI Calculation ---") | |
print(f"BMI: {bmi:.2f}") | |
print("Classification:", classification) | |
if __name == "__main": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from calculatebmi import calculatebmi, classifybmi | |
class TestBMI(unittest.TestCase): | |
def testcalculate_bmi(self): | |
self.assertAlmostEqual(calculate_bmi(70, 175), 22.86, places=2) | |
self.assertAlmostEqual(calculate_bmi(50, 160), 19.53, places=2) | |
self.assertAlmostEqual(calculate_bmi(90, 185), 26.30, places=2) | |
def test_classify_bmi(self): | |
self.assertEqual(classify_bmi(16), "Underweight") | |
self.assertEqual(classify_bmi(22), "Normal weight") | |
self.assertEqual(classify_bmi(27), "Overweight") | |
self.assertEqual(classify_bmi(32), "Obese") | |
if __name == '__main': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment