-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_tracker.py
More file actions
50 lines (40 loc) · 1.45 KB
/
task_tracker.py
File metadata and controls
50 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
tasks = []
while True:
print("\nCommands: add, view, complete, exit")
command = input("Enter command: ").strip().lower()
if command == "add":
task = input("Enter task description: ").strip()
if task:
tasks.append(task)
print(f'Task "{task}" added.')
else:
print("Task cannot be empty.")
elif command == "view":
if not tasks:
print("No tasks available.")
else:
print("\nYour Tasks:")
for i, task in enumerate(tasks, start=1):
print(f"{i}. {task}")
elif command == "complete":
if not tasks:
print("No tasks to complete.")
continue
try:
index = int(input("Enter task number to complete: "))
if 1 <= index <= len(tasks):
completed_task = tasks[index - 1]
# Option 1: Mark task as completed
tasks[index - 1] = "[x] " + completed_task
print(f'Task marked as completed: {completed_task}')
# Option 2 (alternative): Remove task
# del tasks[index - 1]
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
elif command == "exit":
print("Goodbye! 👋")
break
else:
print("Invalid command. Please try again.")