UoPeople Assign 04

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Part 1

You work as a software developer in a company that creates custom software solutions for
various clients. Your company has been approached by an educational client who wants to
develop a function that calculates the length of the hypotenuse of a right triangle given the
lengths of the other two legs as arguments. Your manager has instructed you to use
incremental development to create the necessary function and document each stage of the
development process. After completing the final stage of development, you have to test the
function with different arguments and record the outputs in your Learning Journal.
Code:
import math

# define the function that takes two arguments


def calculate_hypotenuse(a, b):
return math.sqrt(a**2 + b**2)

# The output of hypotenuse(3,4).


a, b = 3, 4
hypotenuse = calculate_hypotenuse(a, b)
print(f"The hypotenuse of the triangle with legs {a} and {b} is {hypotenuse}")

# The output of two additional calls to hypotenuse with different arguments.


print("\n Two additional calls to hypotenuse with different arguments: ")

additional_cases = [(6, 4), (9, 5)]


for a, b in additional_cases:
hypotenuse = calculate_hypotenuse(a, b)
print(f"The hypotenuse of the triangle with legs {a} and {b} is {hypotenuse}")
Output:
The hypotenuse of the triangle with legs 3 and 4 is 5.0

Two additional calls to hypotenuse with different arguments:


The hypotenuse of the triangle with legs 6 and 4 is 7.211102550927978
The hypotenuse of the triangle with legs 9 and 5 is 10.295630140987
Explanation:
Firstly, I define a function which accepts two arguments, `a` and `b`.
Secondly, I implemented the Pythagorean theorem to calculate hypotenuses.
Thirdly, I test the function with the sample arguments and print the result.
Fourthly, I added two more given test cases and records their outputs.
We can run this program to calculate hypotenuse for different sets of triangle leg lengths.
Part 2

You are a software developer who wants to establish yourself as a skilled and versatile
programmer. To achieve this, you have decided to create a work portfolio that showcases your
ability to develop custom software solutions. This portfolio will be your gateway to attract
potential clients and establish yourself as a freelancer.

As part of your portfolio, you plan to create your own function that does some useful
computation using an incremental development approach that will demonstrate your
programming skills and problem-solving abilities. You will document each stage of the
development process, including the code and any test input and output in your Programming
Assignment.

Explanation:
It's a great idea to put together a portfolio that highlights your programming prowess and
analytical thinking. Create a Python software that solves a straightforward but practical
problem to demonstrate incremental development as a starting point. Let's write a program
that determines a number's factorial. It will be divided into phases, with each phase's
development being documented. Here's a Python program following this approach:
Code:
# define the function that calculate the factorial of a number
def calculate_factorial(n):
# Initialize the result to 1
result = 1

# implement the factorial calculation


for i in range(1, n + 1):
result *= i

# return the result


return result

# test the function with sample inputs


x = int(input("Enter the number: "))
factorial = calculate_factorial(x)
print(f"Factorial of {x} is {factorial}")

Output:
Enter the number: 11
Factorial of 11 is 39916800
Explanation:
In this program

The 'calculate_factorial' function is defined in Stage 1.


- Stage 2 uses a for loop to implement the factorial computation.
Stage 3 gives the outcome.
- The function is tested with a sample input in Stage 4 before the result is printed.
Any other meaningful computation that illustrates your abilities can be used in place of the
factorial calculation, and as you gain experience, your portfolio will be gradually expanded to
include increasingly complicated projects.

You might also like