Part 1: Collaboration Review

What are the benefits of a team? Explain some of the diversities that your team has to offer.

  • The benefits of a team include communication, compromise, and the ability to compartmentalize, increasing our efficiency by designating roles to members who may be more proficient at certain skills than others, while also being able to complete multiple tasks simultaneously. Some of the diversities our team has to offer are knowledge of multiple languages and diverse computer science backgrounds.

    Describe how you will facilitate communication amongst group members.

  • We will facilitate communication through Discord, Slack, and regular meetups in person to discuss our roles and monitor our progress.

    How will you hold each person accountable for their portion of the work? Think about dates, review tickets, and peer reviews.

  • We will assign certain dates of which select portions of our work shall be done. We will have daily check-ins with our team to review our work, making sure that each person has contributed to their part.

Part 2: Program Function and Purpose

#Program with an output
print("Hello World")
#Program with an input and output5
greeting = input("Provide a greeting: ")
name = input("Provide a name: ")
print(greeting + " " + name)
#Program with a List
fruits = ["Apple", "Banana", "Grape", "Watermelon", "Cherry", "Strawberry", "Blueberry"]
for fruit in fruits:
    print(fruit)
#Program with a Dictionary
student = {"name": "Kaiyu", "age": 16, "grade": "C"}
print("Name:", student["name"])
print("Age:", student["age"])
print("Grade:", student["grade"])
#Program with an Iteration
s = ""
for i in range(1,10):
    s += str(i) + ""
    print(s)
#Program with a Function to perform mathematical and/or a statistical calculations
def add_numbers(a, b):
    return a + b
def subtract_numbers(a, b):
    return a - b
def multiply_numbers(a, b):
    return a * b
def divide_numbers(a, b):
    if b == 0:
        return "Error: Division by zero is not allowed."
    return a / b
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operation = input("Choose operation (+ for addition, - for subtraction, * for multiplication, / for division): ")
if operation == '+':
    result = add_numbers(num1, num2)
    operation_symbol = "addition"
elif operation == '-':
    result = subtract_numbers(num1, num2)
    operation_symbol = "subtraction"
elif operation == '*':
    result = multiply_numbers(num1, num2)
    operation_symbol = "multiplication"
elif operation == '/':
    result = divide_numbers(num1, num2)
    operation_symbol = "division"
else:
    result = "Invalid operation"
    operation_symbol = ""
if operation_symbol:
    print(f"{num1} {operation} {num2} = {result} (Operation: {operation_symbol})")
else:
    print(result)
#Program with a Conditional
grade = int(input("Input your grade %"))
if grade >= 90:
    print("You have an A")
elif grade >= 80:
    print("You have a B")
elif grade >= 70:
    print("You have a C")
elif grade >= 60:
    print("You have a D")
else:
    print("You have an F")
# Program with Purpose
weightInPounds = input("Input the weight in pounds: ")
weightInKilograms = float(weightInPounds) / 2.205
roundedWeightInKilograms = round(weightInKilograms, 2)
print("The weight in kilograms is " + str(roundedWeightInKilograms))

Part 3: Program Design and Development

Factorial Calculator

Factorial Calculator


Visual illustration of algorithm

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Factorial Calculator</title>
    <style>
        /* Basic CSS for styling the UI */
        body {
            font-family: Arial, sans-serif;
            background-color: #F4F4F4;
        }
        #calculator {
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
        }
        h1 {
            color: #333;
        }
        input[type="number"] {
            width: 95% ;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 10px;
        }
        button {
            background-color: #007BFF;
            color: #fff;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<br>
    <div id="calculator">
        <h1>Factorial Calculator</h1>
        <label for="number">Enter a non-negative integer:</label>
        <input type="number" id="number" min="0" step="1" required>
        <button id="calculate">Calculate Factorial</button>
        <p id="result"></p>
    </div>
<script>
    // Add an event listener to the 'calculate' button
    document.getElementById('calculate').addEventListener('click', function () {
        // Get the input value as a number
        const inputNumber = parseInt(document.getElementById('number').value);
        try {
            // Calculate the factorial using the calculateFactorial function
            const factorialResult = calculateFactorial(inputNumber);
            // Display the factorial result in the 'result' element
            document.getElementById('result').textContent = `The factorial of ${inputNumber} is ${factorialResult}`;
        } catch (error) {
            // Handle errors by displaying an error message in the 'result' element
            document.getElementById('result').textContent = error.message;
        }
    });
    // Function to calculate the factorial
    function calculateFactorial(num) {
        // Check if the input is a non-negative integer
        if (typeof num !== 'number' || num < 0 || Math.floor(num) !== num) {
            throw new Error('Input must be a non-negative integer.');
        }
        // Calculate the factorial using a loop
        let result = 1;
        for (let i = 1; i <= num; i++) {
            result *= i;
        }
        // Return the calculated factorial
        return result;
    }
</script>
<br>
<h1>Visual illustration of algorithm</h1>
<img src="https://ci3.googleusercontent.com/mail-img-att/AIFldNrzyIlbGAOsK_xIKKaIueAf7rSM4XREJNw_ann6mQH40gYRJRb2BYSCA_NllhHR84Vn5G9UcpOw27d0o17XXPfjXbX5W3E6Sw71khrObbL6-komDWoX77K4frKwzVvPY0GLWs1y-3VHRTudFeNzMME50s7_pLtelKJ79f8LkKv7Ycd-gZ--tr-xQjrrfHkfMeIpxeG0zU40yVd1zGCYnFiIEH2rSCjCR8hrbmxO5vThRb3_9qJD_s1KXRGNeHM3bmisMjiMEGqszCpkfDQ7tshVCifCuRXtzltkmwF-v9jDqhd2QAyFrG7mhPLeofsIZTRz-hBUhMgdGKTF8_EDaTs0_IfkHOpt9Ahhgzg512jUv9NZeSVaAwKxIh5Et_kxyjG6b-yy_5_rPuWugwWZ3RFcbNosomh9vWttEV6iqoEcCklaMq4PFpanQd30XOZzD-OWQufTzNGBHUnKGl4PNj4JpFPpIlAfjRZAZ5VFSLo1-9bvf4ZRzO5y5pY2Xqcmhn6Io3hCz63WSVnNfOleWT_vE7V2mN5fUGH7xWu3O1cUcbTqBHk2if4hObgNbQnmnLMiVUtins6GqqrqumVU0G_ymRRbtPkwf6992QKSup0um6hFLJwdJpCSWsMIi-_1rm47ecdM0LN8Nw5jlmQThuxQwiDUffq0fsceGuf0cC9KkLIeSW3bKUuH34zsOExOgEeGaRgB9b2AkFVMfVfxi6cdqY7yTdM2jhkxZdoUtf6NOhUMNhNypVthWxGv-x5svQ6VYwBnXVh2rZ4qc1Npo0yhkfsf7h8EVUOVoYY71Zca6Qsbll15s6b1RMUajWdiBmLx5CaGdFwPlxFSuWBsEjIFAe2-oTvwaGmrs0HG2sE4dq5l7WL8oLqctKpPvAUSe_FKncM0Iqy5lHHsB4Gzf_T3_HKWmqSt5gPFm7SgDEjUVKR7ho7mDybwRHXbc-t3De57m3tZGSq1p4qKS0RdCwjv6r2eqxvykxbVKkjvzvVJG0bj-QWK5aJ6YRNHXU03V0veCYpbu7ZCJ_30xdHkyuuG-aSemVmyWqEpoF_FTwdQJ3S0E78R-tTaBerik_JUQflqRhPcEsIzHP9qPLw3U6bLgvL4pH4qao1YbAz_Iy1v5vSz26nsLZiuDew-Bww=s0-l75-ft">
</body>
</html>

Part 4: Identyfing and Correct Errors

First, we define our function.

This function takes two numbers and divides them.
Here, we also test using non-zero numbers to see if the function works for regular division

# Function to divide two numbers that are inputted.
def divide(a,b):
    # Raise a Value Error if there is division by 0
    if b == 0:
        raise ValueError("Divison by 0 is undefined")
    # Otherwise, return the result
    else:
        output = a / b
    return output

# First we test division with two numbers that can be divided to ensure that the function works for regular division
result = divide(6,3)
assert result == 2, "Expected result for 6 / 3 is 2, but got {}".format(result)
print(f"Test passed: divide(6, 3) correctly returned 2")

Now we can test, using a try/catch statement first.

Here we force the function to do division by 0 using a try statement.
If there is a Value Error, we know that the function worked properly.

# Here we test to see if the function works when encountering division by 0 using try/catch statements
try:
    result = divide(8, 0)
    print("Test failed: Expected ValueError, but got result:", result)
except ValueError as e:
    print("Test passed:", str(e))

Now we test using a if/else statement.

Here we force the function to do division by 0 using a if statement.
If an output is returned from the function, the function has failed, but if there is no output then the function passed.

# Here we test to see if the function works when encountering division by 0 using if/else statements
result = None
if 0!=0:
    result = divide(8, 0)
if result is not None:
    print("Test failed: Expected ValueError, but got result:", result)
else:
    print("Test passed: divide(8, 0) correctly handled division by zero.")