Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion labs/lab_1/lab_1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand Down
12 changes: 9 additions & 3 deletions labs/lab_1/lab_1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down