From 2b31d1dbed5b08b377e1a0264fca13933475d1a0 Mon Sep 17 00:00:00 2001 From: Suvina Date: Thu, 19 Mar 2026 08:29:22 -0500 Subject: [PATCH 1/2] Add name --- 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..e0d1ed94 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 = "Suvina Vijayendran" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From 9c26ca71320346a5dee91d179248d9dbd7d3bd40 Mon Sep 17 00:00:00 2001 From: Suvina Date: Thu, 19 Mar 2026 11:21:39 -0500 Subject: [PATCH 2/2] fixing input error --- labs/lab_1/lab_1b.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..0bdcd4f6 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -36,14 +36,20 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: raise ValueError("Cannot divide by zero.") 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: ")) + 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