From e743cadd5a2d8c5f128fcdd03599777897802783 Mon Sep 17 00:00:00 2001 From: Yash-Khadepauu Date: Fri, 26 Sep 2025 03:45:31 +0530 Subject: [PATCH 1/3] Completed all 5 projects --- calculator/main.py | 25 +++++++++++++++++++------ convert-distance/main.py | 15 +++++++++------ digital-clock/main.py | 7 ++++--- pick-color/main.py | 12 ++++++++---- to-do/main.py | 25 ++++++++++++++++++++++--- 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/calculator/main.py b/calculator/main.py index 43bf23b..faf1baf 100644 --- a/calculator/main.py +++ b/calculator/main.py @@ -2,20 +2,22 @@ # Performs basic arithmetic operations based on user input def add(a, b): - # TODO: Return sum of a and b + return a + b pass def subtract(a, b): - # TODO: Return difference of a and b + return a - b pass def multiply(a, b): - # TODO: Return product of a and b + return a * b pass def divide(a, b): - # TODO: Return quotient of a and b - # Handle division by zero + if b == 0: + return "Error: division by 0" + else: + return a/b pass def main(): @@ -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 == "+": + answer = add(num1, num2) + elif operator == "-": + answer = subtract(num1, num2) + elif operator == "*": + answer = multiply(num1, num2) + elif operator == "/": + answer = divide(num1, num2) + else: + answer = "Error: invalid operator" + + print("Answer: ", answer) except ValueError: print("Invalid number entered.") diff --git a/convert-distance/main.py b/convert-distance/main.py index f6bcfe8..3bbd95d 100644 --- a/convert-distance/main.py +++ b/convert-distance/main.py @@ -2,15 +2,18 @@ # Convert between kilometers, meters, and centimeters def km_to_m(km): - # TODO: Convert kilometers to meters + m = km * 1000 + print("km = ", m, "m") pass def m_to_cm(m): - # TODO: Convert meters to centimeters + cm = m * 100 + print("m = ", cm, "cm") pass def cm_to_km(cm): - # TODO: Convert centimeters to kilometers + km = cm / 100000 + print("cm = ", km, "km") pass def main(): @@ -24,13 +27,13 @@ def main(): if choice == "1": km = float(input("Enter distance in kilometers: ")) - # Call conversion function + km_to_m(km) elif choice == "2": m = float(input("Enter distance in meters: ")) - # Call conversion function + m_to_cm(m) elif choice == "3": cm = float(input("Enter distance in centimeters: ")) - # Call conversion function + cm_to_km(cm) else: print("Invalid choice!") diff --git a/digital-clock/main.py b/digital-clock/main.py index 986773e..440cb5a 100644 --- a/digital-clock/main.py +++ b/digital-clock/main.py @@ -5,7 +5,7 @@ import time def get_current_time(): - # TODO: Return the current system time in formatted string + return datetime.now().strftime("%H:%M:%S") pass def main(): @@ -13,8 +13,9 @@ def main(): try: while True: - # Get current time and display it - # Use time.sleep(1) to update every second + current_time = get_current_time() + print("\r" + current_time, end="") + time.sleep(1) pass except KeyboardInterrupt: print("\nClock stopped.") diff --git a/pick-color/main.py b/pick-color/main.py index 4286499..5699b92 100644 --- a/pick-color/main.py +++ b/pick-color/main.py @@ -4,16 +4,20 @@ import random def get_random_color(): - # TODO: Return a random color from the list colors = ["Red", "Green", "Blue", "Yellow", "Purple", "Orange"] + return random.choice(colors) pass def main(): print("Random Color Picker") - while True: - input("Press Enter to pick a color (or Ctrl+C to quit)...") - # Call the random color function and display the result + try: + while True: + input("Press Enter to pick a color (or Ctrl+C to quit)...") + color = get_random_color() + print("Your color is: ", color) + except KeyboardInterrupt: + print("\nStopped.") if __name__ == "__main__": main() diff --git a/to-do/main.py b/to-do/main.py index a1fcc80..ad61604 100644 --- a/to-do/main.py +++ b/to-do/main.py @@ -9,15 +9,34 @@ def show_menu(): print("4. Exit") def add_task(tasks): - # TODO: Ask user for a task and append to the list + task = input("Enter a new task: ") + tasks.append(task) + print("Task added.") pass def remove_task(tasks): - # TODO: Show task list and allow user to remove by index + if len(tasks) == 0: + print("No tasks to remove.") + pass + view_tasks(tasks) + try: + index = int(input("Enter the task number to remove: ")) + if 1 <= index <= len(tasks): + tasks.pop(index - 1) + print("Task removed.") + else: + print("Invalid task number.") + except ValueError: + print("Error: please enter a valid number") pass def view_tasks(tasks): - # TODO: Display current list of tasks + if len(tasks) == 0: + print("No tasks added yet.") + else: + print("\nYour Tasks:") + for task in tasks: + print(task) pass def main(): From 52cf2ad7cb551dfd0442b62bbffaac70cd357099 Mon Sep 17 00:00:00 2001 From: Yash-Khadepauu Date: Fri, 26 Sep 2025 03:53:48 +0530 Subject: [PATCH 2/3] Updated clock and color project --- digital-clock/main.py | 2 +- pick-color/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/digital-clock/main.py b/digital-clock/main.py index 440cb5a..bb4e62d 100644 --- a/digital-clock/main.py +++ b/digital-clock/main.py @@ -9,7 +9,7 @@ def get_current_time(): pass def main(): - print("Digital Clock - Press Ctrl+C to stop\n") + print("Digital Clock - Press Ctrl+C to stop") try: while True: diff --git a/pick-color/main.py b/pick-color/main.py index 5699b92..f8d9dd9 100644 --- a/pick-color/main.py +++ b/pick-color/main.py @@ -17,7 +17,7 @@ def main(): color = get_random_color() print("Your color is: ", color) except KeyboardInterrupt: - print("\nStopped.") + print("Stopped.") if __name__ == "__main__": main() From 102e116112e66fcbdb7bec66383606f5057b58a5 Mon Sep 17 00:00:00 2001 From: Yash-Khadepauu Date: Fri, 26 Sep 2025 04:02:54 +0530 Subject: [PATCH 3/3] Completed the To-Do List project --- to-do/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/to-do/main.py b/to-do/main.py index ad61604..7ab18cc 100644 --- a/to-do/main.py +++ b/to-do/main.py @@ -34,9 +34,11 @@ def view_tasks(tasks): if len(tasks) == 0: print("No tasks added yet.") else: - print("\nYour Tasks:") + count = 1 + print(tasks) for task in tasks: - print(task) + print(count, ". ", task) + count += 1 pass def main():