Skip to content
Open
31 changes: 22 additions & 9 deletions calculator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.")
Expand Down
8 changes: 7 additions & 1 deletion convert-distance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
4 changes: 4 additions & 0 deletions digital-clock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

def get_current_time():
# TODO: Return the current system time in formatted string
print (datetime.now())

pass

def main():
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions pick-color/main.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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()
4 changes: 4 additions & 0 deletions to-do/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down