0% found this document useful (0 votes)
8 views10 pages

Part I

Uploaded by

lilskit4life
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Part I

Uploaded by

lilskit4life
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PART I

Stage Development I:

Defining the function and hypotenuse argument representing the lengths of the other two

legs of a right triangle. Started out by importing the math module to access the sqrt function for

calculating the square root.

import math

def hypotenuse (a, b):

return math.sqrt(a**2 + b**2)

Stage Development II:

Stage 2: Calculation of Hypotenuse In this stage, we calculate the length of the

hypotenuse using the Pythagorean theorem, which states that the square of the hypotenuse is

equal to the sum of the squares of the other two legs. We assign the calculated value to a variable

hyp.

# Test call

print(hypotenuse(3, 4))

Output: 5.0

A, b = 3, 4

Explanation:
Calculates the hypotenuse of a right triangle using the Pythagorean theorem. Args: a (float):

Length of the first leg. b (float): Length of the second leg. Returns: float: Length of the

hypotenuse. """

Stage Development III:

Testing other inputs and each given output

print(hypotenuse(3, 4)) # Output: 5.0

print(hypotenuse(5, 12)) # Output: 13.0

print(hypotenuse(8, 15)) # Output: 17.0

Explanation:

I defined each function by using a and b as variables.

Then I used the pythagorean theorem to implement the function in Python code.

I added given records for other random inputs to get new outputs.

This program can be run multiple times to get the hypotenuse for any function.

PART II

Portfolio Function Development Plan

For the portfolio, I chose to create a function that calculates the Body Mass Index (BMI) and

provides a health classification based on the calculated value. BMI is a widely used metric to
assess health risks related to weight and height. This would be a good portfolio showing for a

company that is health based and looking for developers.

This function is practical and demonstrates computational skills, conditional logic, and user-

focused output formatting.

Function Requirements

1. Accept two inputs: `weight` (in kilograms) and `height` (in meters).

2. Compute BMI using the formula:

\[ \text{BMI} = \frac{\text{weight}}{\text{height}^2}

\]

3. Return the BMI value and a health classification:

- BMI < 18.5: "Underweight"

- 18.5 ≤ BMI < 24.9: "Normal weight"

- 25.0 ≤ BMI < 29.9: "Overweight"

- BMI ≥ 30.0: "Obesity"

Incremental Development Stages:

Stage 1: Function and Structure

We create the function:


def calculate_bmi(weight, height):

pass # Placeholder for implementation

# Test call

print(calculate_bmi(70, 1.75)) # Expected output: None

Output:

None

Stage 2: Basic BMI Calculation

Add the formula for BMI calculation.

def calculate_bmi(weight, height):

return weight / (height 2)

# Test call

print(calculate_bmi(70, 1.75)) # Expected output: 22.857142857142858


Output:

22.857142857142858

This verifies that the BMI formula works as expected.

Stage 3: Add Health Classification

Incorporate conditional statements to classify the BMI.

def calculate_bmi(weight, height):

bmi = weight / (height 2)

if bmi < 18.5:

category = "Underweight"

elif 18.5 <= bmi < 24.9:

category = "Normal weight"

elif 25.0 <= bmi < 29.9:

category = "Overweight"

else:

category = "Obesity"

return bmi, category


# Test call

print(calculate_bmi(70, 1.75)) # Expected output: (22.857142857142858, 'Normal weight')

Output:

(22.857142857142858, 'Normal weight')

Stage 4: Format the Output

Refine the function to format the BMI to 2 decimal places and improve readability.

def calculate_bmi(weight, height):

Calculates BMI and returns the health classification.

Args:

weight (float): Weight in kilograms.

height (float): Height in meters.

Returns:

tuple: Formatted BMI and health classification.

bmi = weight / (height 2)

bmi = round(bmi, 2) # Format to 2 decimal places


if bmi < 18.5:

category = "Underweight"

elif 18.5 <= bmi < 24.9:

category = "Normal weight"

elif 25.0 <= bmi < 29.9:

category = "Overweight"

else:

category = "Obesity"

return bmi, category

# Test call

print(calculate_bmi(70, 1.75)) # Expected output: (22.86, 'Normal weight')

Output:

(22.86, 'Normal weight')

Final Testing

# Test 1: Underweight

print(calculate_bmi(50, 1.75)) # Expected output: (16.33, 'Underweight')


Output:

(16.33, 'Underweight')

# Test 2: Overweight

print(calculate_bmi(80, 1.75)) # Expected output: (26.12, 'Overweight')

Output:

(26.12, 'Overweight')

# Test 3: Obesity

print(calculate_bmi(100, 1.75)) # Expected output: (32.65, 'Obesity')

Output:

(32.65, 'Obesity')

Final Code

def calculate_bmi(weight, height):


Calculates BMI and returns the health classification.

Args:

weight (float): Weight in kilograms.

height (float): Height in meters.

Returns:

tuple: Formatted BMI and health classification.

bmi = weight / (height 2)

bmi = round(bmi, 2) # Format to 2 decimal places

if bmi < 18.5:

category = "Underweight"

elif 18.5 <= bmi < 24.9:

category = "Normal weight"

elif 25.0 <= bmi < 29.9:

category = "Overweight"

else:

category = "Obesity"

return bmi, category

Final Outputs

1. calculate_bmi(70, 1.75)` → (22.86, 'Normal weight')

2. calculate_bmi(50, 1.75)` → (16.33, 'Underweight')

3. `calculate_bmi(100, 1.75)` → (32.65, 'Obesity')


This function demonstrates practical application for a company portfolio as this can be used to

show off for a health company, my function allows for the primary calculation of BMI to weight

making it good for everyday use.

You might also like