diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..4ab6b4d9 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,6 +1,6 @@ """ lab_1a.py - +This is to simulate a change made on a robot: robot_speed = 8 # m/s 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. """ @@ -8,9 +8,10 @@ def main(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Kishan Paschapur" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") if __name__ == "__main__": main() +# --- IGNORE --- \ No newline at end of file diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..d1997699 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -42,9 +42,27 @@ 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() +while True: + try: + num1 = float(input("Enter the first number: ")) + break + except ValueError: + print("That's not a number. Please try again.") + +while True: + try: + num2 = float(input("Enter the second number: ")) + break + except ValueError: + print("That's not a number. Please try again.") + + # Ask the user for the operation +while True: + operation = input("Enter the operation (add, subtract, multiply, divide): ").lower() + if operation == "add" or operation == "subtract" or operation == "multiply" or operation == "divide": + break + else: + print("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") # Perform the calculation and display the result result = simple_calculator(operation, num1, num2)