diff --git a/calculator/main.py b/calculator/main.py index 43bf23b..c88ab2e 100644 --- a/calculator/main.py +++ b/calculator/main.py @@ -2,21 +2,23 @@ # Performs basic arithmetic operations based on user input def add(a, b): - # TODO: Return sum of a and b - pass + # Return sum of a and b + return a + b def subtract(a, b): - # TODO: Return difference of a and b - pass + # Return difference of a and b + return a - b def multiply(a, b): - # TODO: Return product of a and b - pass + # Return product of a and b + return a * b def divide(a, b): - # TODO: Return quotient of a and b + # Return quotient of a and b # Handle division by zero - pass + if b == 0: + return "Error: Division by zero!" + return a / b def main(): print("Simple Calculator") @@ -27,7 +29,18 @@ def main(): operator = input("Enter operator: ") num2 = float(input("Enter second number: ")) - # Match the operator with the correct function + if operator == '+': + result = add(num1, num2) + elif operator == '-': + result = subtract(num1, num2) + elif operator == '*': + result = multiply(num1, num2) + elif operator == '/': + result = divide(num1, num2) + else: + result = "Invalid operator!" + + print("Result:", result) except ValueError: print("Invalid number entered.") diff --git a/convert-distance/main.py b/convert-distance/main.py index f6bcfe8..b663b14 100644 --- a/convert-distance/main.py +++ b/convert-distance/main.py @@ -3,14 +3,17 @@ def km_to_m(km): # TODO: Convert kilometers to meters + return (km*1000) pass def m_to_cm(m): # TODO: Convert meters to centimeters + return (m*100) pass def cm_to_km(cm): # TODO: Convert centimeters to kilometers + return (cm/100000) pass def main(): @@ -24,15 +27,18 @@ def main(): if choice == "1": km = float(input("Enter distance in kilometers: ")) + result = km_to_m(km) # Call conversion function elif choice == "2": m = float(input("Enter distance in meters: ")) + result = m_to_cm(m) # Call conversion function elif choice == "3": cm = float(input("Enter distance in centimeters: ")) + result = cm_to_km(cm) # Call conversion function else: print("Invalid choice!") - + print("Result:",result) if __name__ == "__main__": main() diff --git a/digital-clock/main.py b/digital-clock/main.py index 986773e..14b5ebb 100644 --- a/digital-clock/main.py +++ b/digital-clock/main.py @@ -6,6 +6,8 @@ def get_current_time(): # TODO: Return the current system time in formatted string + print (datetime.now()) + pass def main(): @@ -14,6 +16,8 @@ def main(): try: while True: # Get current time and display it + get_current_time() + time.sleep(1) # Use time.sleep(1) to update every second pass except KeyboardInterrupt: diff --git a/pick-color/main.py b/pick-color/main.py index 4286499..0a2c51b 100644 --- a/pick-color/main.py +++ b/pick-color/main.py @@ -1,11 +1,12 @@ # Color Picker Simulator # Picks a random color from a predefined list -import random +from random import randrange def get_random_color(): # TODO: Return a random color from the list colors = ["Red", "Green", "Blue", "Yellow", "Purple", "Orange"] + print(colors[randrange(5)]) pass def main(): @@ -14,6 +15,6 @@ def main(): while True: input("Press Enter to pick a color (or Ctrl+C to quit)...") # Call the random color function and display the result - + print(get_random_color()) if __name__ == "__main__": main() diff --git a/to-do/main.py b/to-do/main.py index a1fcc80..b6b158e 100644 --- a/to-do/main.py +++ b/to-do/main.py @@ -9,14 +9,18 @@ def show_menu(): print("4. Exit") def add_task(tasks): + task = input("Enter a task") + tasks.append(task) # TODO: Ask user for a task and append to the list pass def remove_task(tasks): + tasks.pop() # TODO: Show task list and allow user to remove by index pass def view_tasks(tasks): + print(tasks) # TODO: Display current list of tasks pass