You are on page 1of 2

Tasks

Part 1

The first stage of development is to design the function. We need to define the function's
name, parameters, and return type. The function will be named hypotenuse and will take
two parameters, a and b, representing the lengths of the two legs of the right triangle. The
function will return the length of the hypotenuse.
def hypotenuse(a, b):
return a + b

The next stage is to test the function. We will test the function with the input (3, 4) and
record the output in our Learning Journal.
print(hypotenuse(3, 4))

Output: 6

The third stage is to refactor the function. We will modify the function to calculate the
length of the hypotenuse using the Pythagorean theorem.
def hypotenuse(a, b):
return (a**2 + b**2)**0.5

We will test the refactored function with the same input (3, 4) and record the output in our
Learning Journal.
print(hypotenuse(3, 4))

Output 5

The final stage is to test the function with additional arguments. We will test the function
with the inputs (5, 12) and (8, 15) and record the outputs in our Learning Journal.
print(hypotenuse(5, 12))

output 13
print(hypotenuse(8, 15))

Output 17

In conclusion, we have successfully developed a function that calculates the length of the
hypotenuse of a right triangle given the lengths of the other two legs as arguments. We have
documented each stage of the development process and tested the function with different
arguments.

Part 2

Design the function

Programme
def calculate_area(width, height):
return width * height

Test function

The next stage is to test the function. We will test the function with the input (5, 10) and
record the output in our Programming Assignment
print(calculate_area(5, 10))

Output 50

The third stage is to refactor the function. We will modify the function to calculate the area
of a rectangle using the formula A = w * h.
def calculate_area(width, height):
return width * height

We will test the refactored function with the same input (5, 10) and record the output in our
Programming Assignment.
print(calculate_area(5, 10))

Output: 50

The final stage is to test the function with additional arguments. We will test the function
with the inputs (10, 20) and (5, 15) and record the outputs in our Programming Assignment.
print(calculate_area(10, 20))

output: 200
print(calculate_area(5, 15))

Output: 75

You might also like