Part 1
Stage 1: Function Definition
In this stage, we define the function hypotenuse that takes two arguments representing the
lengths of the other two legs of a right triangle. We import the math module to access the square
root function.
Stage 2: Calculation
In this stage, we calculate the length of the hypotenuse using the Pythagorean theorem. We
square each leg, sum them, and then take the square root of the result.
Stage 3: Testing
In this stage, we test the function with different inputs to ensure it produces the expected outputs.
We can use the print function to display the results.
Outputs
The output of hypotenuse (3, 4) is 5.0.
The output of hypotenuse (5, 12) is 13.0.
The output of hypotenuse (8, 15) is 17.0.
Each test verifies that the function computes values as expected given triangle sides with known
hypotenuses. These methods allow me to gradually create the code, verify each component
before adding complexity, and minimize errors at each stage. This technique helps build a
reliable function and understand its operation.
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.
To demonstrate programming and problem-solving skills, I created find_primes_in_range. It
calculates all prime integers in a range. Clarity and optimization are prioritized in incremental
development. This article describes each development stage.
Stage 1: Define the Problem and Plan
The goal is to find all prime numbers within a given range. A prime number is a number greater
than 1 that has no divisors other than 1 and itself. The function will:
1. Take two integers as input: the start and end of the range.
2. Validate the input.
3. Compute and return a list of prime numbers within the range.
Stage 2: Initial Implementation
The initial step is creating a function that identifies whether a single number is prime
Explanation of the code: The is prime function checks divisors up to the square root of the
number for efficiency. It returns True for primes and False otherwise.
Stage 3: Extend Functionality
Build on is prime to find all primes within a specified range.
Explanation of the code: The function iterates over the range, checking each number with
is_prime. Valid inputs return a list of primes; invalid ranges return an error message.
Stage 4: Optimize and Finalize
Incorporate optimizations to handle edge cases and improve readability.
Outputs with Explanations
o Test Case 1: The primes between 10 and 20 are [11, 13, 17, 19].
o Test Case 2: The primes between 1 and 10 are [2, 3, 5, 7]. The function ensures the range
starts at 2 since no numbers below 2 are prime.
o Test Case 3: An invalid range produces the error message "Invalid range: start must be
less than or equal to end.".
Conclusion:
By documenting each stage of the development and testing process, I exhibit professional
programming methods and methodical problem-solving, both of which are necessary for
obtaining freelance clients and developing a good software development portfolio.
References
Downey, A. (2015). Think Python: How to think like a computer scientist. Needham,
Massachusetts: Green Tree Press.
Reference
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
[Link]