diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..5e20941d 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,14 +3,16 @@ 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(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Nolan Purcell" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") + print("Hello! My name is Nolan Purcell and I am a freshman from Florida. I like to play golf and play video games with my friends.") if __name__ == "__main__": main() diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..660745e1 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -8,6 +8,21 @@ and prints the result to the terminal window. """ +def sanitize_num(prompt: str) -> float: + while True: + try: + number = float (input (prompt)) + return number + except ValueError: + print("Invalid input. Please enter a valid number.") + +def sanitize_op(prompt: str) -> str: + while True: + operation = str (input (prompt)) + if operation == "add" or operation == "subtract" or operation =="multiply" or operation =="divide": + return operation + else: + print("Invalid operation. Please enter a valid operation.") def simple_calculator(operation: str, num1: float, num2: float) -> float: """ @@ -42,9 +57,9 @@ 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: ")) - operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() + num1 = sanitize_num("Enter the first number: ") + num2 = sanitize_num("Enter the second number: ") + operation = sanitize_op("Enter the operation (add, subtract, multiply, divide): ").strip().lower() # Perform the calculation and display the result result = simple_calculator(operation, num1, num2)