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
7 changes: 4 additions & 3 deletions labs/lab_1/lab_1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
def main():
print("Hello World!")

name = "" # TODO: Insert your name between the double quotes

print(f"{name}, Welcome to the CSS course!")
name = "sahithi A" # TODO: Insert your name between the double quotes
introduction = f"Hello, My name is {name} and I am a student in the CSS course. checking merge conflict, commit from local" # TODO: Insert your name between the double quotes
print(f"{name} , Welcome to the CSS course!")
print(f"Introduction: {introduction} , Welcome to the CSS course!")

if __name__ == "__main__":
main()
39 changes: 27 additions & 12 deletions labs/lab_1/lab_1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

"""

from sqlalchemy import false


def simple_calculator(operation: str, num1: float, num2: float) -> float:
"""
Function that takes in two numbers and an operation (add, subtract, multiply, divide),
Expand Down Expand Up @@ -38,18 +41,30 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float:
raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.")

def main():
print("===== Simple Calculator =====")

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()

# Perform the calculation and display the result
result = simple_calculator(operation, num1, num2)
print(f"The result of {operation}ing {num1} and {num2} is: {result}")

# Loop indefinitely until we reach the 'break' statement
while True:
try:
# 1. Get Numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

# 2. Get Operation
operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower()

# 3. Attempt Calculation
# We call this inside the try block to catch "divide by zero" or "invalid operation"
result = simple_calculator(operation, num1, num2)

# 4. Success! Print and exit the loop
print(f"\nThe result of {operation}ing {num1} and {num2} is: {result}")
break

except ValueError as e:
# This catches both non-numeric inputs and our custom errors from the function
print(f"\n[Error]: {e}")
print("Please try again.\n")

if __name__ == "__main__":
main()
main()