0% found this document useful (0 votes)
35 views3 pages

CS 1101 Unit 4

Programing Fundamentals Unit 4 Assignment

Uploaded by

sarahhauya1
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)
35 views3 pages

CS 1101 Unit 4

Programing Fundamentals Unit 4 Assignment

Uploaded by

sarahhauya1
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/ 3

University of the People

Sarah Hauya

Unit 4 Programming Assignment

Muhammad Anwa, Instructor

Due by 4th October, 2024

Part 1

Stage 1: Project Setup and Function Signature

In this stage, one needs to set up the project and define the function's signature (name, parameters, and
return type). Here's how it might look in Python:def calculate_hypotenuse(a, b): pass # Placeholder for
the actual implementation.

Stage 2: Input Validation

Before calculating the hypotenuse, it is recommended that one need to validate the input values to
ensure they are valid with accurate lengths for the legs of a right triangle. Thus, this stage needs us to
add input validation code:def calculate_hypotenuse(a, b): if a <= 0 or b <= 0: raise ValueError("Lengths
of legs must be greater than zero") pass # Placeholder for the actual implementation

Stage 3: Hypotenuse Calculation

The next step is to calculate the hypotenuse using the Pythagorean theorem in this stage:import
mathdef calculate_hypotenuse(a, b): if a <= 0 or b <= 0: raise ValueError("Lengths of legs must be
greater than zero") return math.sqrt(a**2 + b**2)

Stage 4: Testing and Documentation


Now that we have our function, it's essential to thoroughly test it with different arguments
anddocument the results in your Learning Journal. For example:# Test cases
print(calculate_hypotenuse(3, 4)) # Expected output: 5.0 print(calculate_hypotenuse(5, 12)) # Expected
output: 13.0 print(calculate_hypotenuse(8, 15)) # Expected output: 17.0```After running these tests,
record the actual outputs in your Learning Journal and compare themwith the expected results. Make
sure to note if any issues or errors occur during testing.Stage 5: Finalization and ReviewIn this final
stage, review your code and documentation to ensure everything is in order. Check that all tests have
passed and that your code is well-documented. This incremental developmentapproach ensures that
each stage of the function's development is tested and validated beforemoving on to the next. It helps
catch and address issues early in the process, resulting in a morerobust and reliable function for your
educational client.Part 2Creating a work portfolio is an excellent way to showcase your programming
skills and attract potential clients as a freelancer. Let's go through the process of creating a custom
softwaresolution as part of your portfolio using an incremental development approach. For this
example,we'll create a Python function that calculates the factorial of a given number.Stage 1: Project
Setup and Function SignatureIn this initial stage, set up the project and define the function's
signature:def calculate_factorial(n): pass # Placeholder for the actual implementation

Stage 2: Input Validation

Next, add input validation code to ensure that the input is a non-negative integer:def
calculate_factorial(n): if not isinstance(n, int) or n < 0: raise ValueError("Input must be a non-negative
integer") pass # Placeholder for the actual implementationStage 3: Base Case Handling

Factorial calculation typically involves recursive logic with a base case. Implement the base casewhere
`n` is 0 or 1:def calculate_factorial(n): if not isinstance(n, int) or n < 0: raise ValueError("Input must be a
non-negative integer") if n == 0 or n == 1: return 1 pass # Placeholder for the recursive caseStage 4:
Recursive Case Now, add the recursive logic for calculating the factorial:def calculate_factorial(n): if not
isinstance(n, int) or n < 0: raise ValueError("Input must be a non-negative integer") if n == 0 or n == 1:
return 1 return n * calculate_factorial(n - 1)

Stage 5: Testing and Documentation

Test your function with various inputs and document the results in your ProgrammingAssignment:# Test
cases print(calculate_factorial(0)) # Expected output: 1 print(calculate_factorial(1)) # Expected output: 1
print(calculate_factorial(5)) # Expected output: 120 print(calculate_factorial(10)) # Expected output:
3628800After running these tests, record the actual outputs in your Programming Assignment
andcompare them with the expected results. Make sure to note if any issues or errors occur
duringtesting.

Stage 6: Finalization and Review

In this final stage, review your code and documentation to ensure everything is in order. Check that all
tests have passed and that your code is well-documented. You can also consider addingcomments and
explanations to clarify the code for potential clients who review your portfolio.By following this
incremental development approach, you'll demonstrate your programmingskills and problem-solving
abilities to potential clients. Your portfolio will serve as evidence of your capability to develop custom
software solutions, which will help you establish yourself as askilled and versatile.

You might also like