From e0d170601306e3f5561ca5dd6a0ec8fa713edc4e Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Sat, 21 Mar 2026 19:48:14 -0400 Subject: [PATCH 1/2] Add robot speed comment in lab_1a.py Added a comment about robot speed to the lab description. --- labs/lab_1/lab_1a.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..407746c4 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,6 +3,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 """ def main(): From 18035ed4a02ba1bc673a91c5b9fa8b544b19c914 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Sat, 21 Mar 2026 19:58:27 -0400 Subject: [PATCH 2/2] Update lab_1b.py --- labs/lab_1/lab_1b.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..7b902fe7 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -37,13 +37,20 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: else: raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") +def request_sanitized_number(prompt: str) -> float: + 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: ")) + # Ask the user for input and ensure both numbers are valid floats. + num1 = request_sanitized_number("Enter the first number: ") + num2 = request_sanitized_number("Enter the second number: ") operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() # Perform the calculation and display the result