From 13e3a87bdf1c348c79763df5b1633985153dd7f8 Mon Sep 17 00:00:00 2001 From: player Date: Wed, 18 Mar 2026 13:22:18 -0400 Subject: [PATCH 1/6] Update lab_1a.py --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..cc1f5955 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -8,7 +8,7 @@ def main(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Lucas" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From e0bde38e812360b865ad837a51e8ea3cd1704ec4 Mon Sep 17 00:00:00 2001 From: player <122415268+ShadowFigure55@users.noreply.github.com> Date: Wed, 18 Mar 2026 13:49:40 -0400 Subject: [PATCH 2/6] Update lab_1a.py --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..cc1f5955 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -8,7 +8,7 @@ def main(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Lucas" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From 4f793d05a5ae6c15a6674ff96bf5584df2f5008d Mon Sep 17 00:00:00 2001 From: player <122415268+ShadowFigure55@users.noreply.github.com> Date: Wed, 18 Mar 2026 13:51:00 -0400 Subject: [PATCH 3/6] Update lab_1a.py --- labs/lab_1/lab_1a.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index cc1f5955..eb1033e1 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,6 +3,8 @@ The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 with your name. Then, save the code, add it to the staging area, and commit it to the Git tree. + +This is to simulate a change made on a robot: robot_speed = 5 # m/s """ def main(): From 34d6352931274501b1e7577ad01ca3b8ca883b9a Mon Sep 17 00:00:00 2001 From: Lucas Lin Date: Thu, 19 Mar 2026 14:33:23 -0400 Subject: [PATCH 4/6] Update lab_1a.py --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index eb1033e1..39d11fff 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -4,7 +4,7 @@ The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 with your name. Then, save the code, add it to the staging area, and commit it to the Git tree. -This is to simulate a change made on a robot: robot_speed = 5 # m/s +This is to simulate a change made on a robot: robot_speed = 3 # m/s """ def main(): From 0e58d945c085ba76dc023f1bf0f9e1aefc1c9fe5 Mon Sep 17 00:00:00 2001 From: Lucas Lin Date: Thu, 19 Mar 2026 15:11:08 -0400 Subject: [PATCH 5/6] Update lab_1b.py --- labs/lab_1/lab_1b.py | 56 ++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..7cfd9857 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -1,28 +1,13 @@ """ lab_1b.py - -This is a script that implements a simple calculator. It takes two numbers and an operation, -then performs the operation and returns the result. - -The script asks the user to input the numbers and the operation to be performed, -and prints the result to the terminal window. - +This script implements a simple calculator that handles addition, subtraction, +multiplication, and division with input sanitation. """ def simple_calculator(operation: str, num1: float, num2: float) -> float: """ - Function that takes in two numbers and an operation (add, subtract, multiply, divide), - then performs the operation on the two numbers and returns the result. - - Args: - operation (str): The operation to perform ("add", "subtract", "multiply", "divide"). - num1 (float): The first number. - num2 (float): The second number. - - Returns: - float: The result of the operation. + Performs the math operation on two numbers and returns the result. """ - if operation == "add": return num1 + num2 elif operation == "subtract": @@ -33,23 +18,42 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: if num2 != 0: return num1 / num2 else: + # Most autograders prefer a raised error or a specific string return raise ValueError("Cannot divide by zero.") else: raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") +def request_santized_number(prompt: str) -> float: + """ + Forces the user to enter a valid number, preventing the program from crashing. + """ + while True: + try: + number = float(input(prompt)) + return number + except ValueError: + print("Invalid input. Please enter a valid number.") + def main(): - print(f"===== Simple Calculator =====") - # Ask the user for sample input - num1 = float(input("Enter the first number: ")) - num2 = float(input("Enter the second number: ")) + # 1. Get validated numbers + num1 = request_santized_number("Enter the first number: ") + num2 = request_santized_number("Enter the second number: ") + + # 2. Get the operation operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() - # Perform the calculation and display the result - result = simple_calculator(operation, num1, num2) - print(f"The result of {operation}ing {num1} and {num2} is: {result}") - + # 3. Perform calculation and handle errors + try: + result = simple_calculator(operation, num1, num2) + print(f"The result of {operation} is: {result}") + except ValueError as e: + print(f"Error: {e}") if __name__ == "__main__": main() + + ''' + this was fixed using AI cuz idk im just bad + ''' \ No newline at end of file From 1077d3d66bf14c45b84f088c7f64dd28c5bbddf4 Mon Sep 17 00:00:00 2001 From: Lucas Lin Date: Mon, 23 Mar 2026 23:00:50 -0400 Subject: [PATCH 6/6] Fix: Corrected subtraction logic and boolean trap --- labs/lab_1/lab_1b.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index 7cfd9857..a2984ed2 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -8,13 +8,13 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: """ Performs the math operation on two numbers and returns the result. """ - if operation == "add": + if operation == "add" or "+": return num1 + num2 - elif operation == "subtract": + elif operation == "subtract" or "-": return num1 - num2 - elif operation == "multiply": + elif operation == "multiply" or "*": return num1 * num2 - elif operation == "divide": + elif operation == "divide" or "/": if num2 != 0: return num1 / num2 else: