-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTasks
More file actions
69 lines (57 loc) · 1.96 KB
/
Copy pathTasks
File metadata and controls
69 lines (57 loc) · 1.96 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Task:
def __init__(self, title):
self.title = title
self.completed = False
def complete(self):
self.completed = True
def __str__(self):
status = "Done" if self.completed else "Pending"
return f"{self.title} - {status}"
def main():
tasks = []
while True:
print("\n1. Add Task")
print("2. List Tasks")
print("3. Mark Task as Completed")
print("4. Delete Task")
print("5. Exit")
choice = input("Enter your choice (1-5): ")
if choice == '1':
title = input("Enter task title: ")
tasks.append(Task(title))
print("Task added!")
elif choice == '2':
if tasks:
print("\nTasks:")
for idx, task in enumerate(tasks, 1):
print(f"{idx}. {task}")
else:
print("No tasks.")
elif choice == '3':
if tasks:
idx = int(input("Enter task number to mark as completed: ")) - 1
if 0 <= idx < len(tasks):
tasks[idx].complete()
print("Task marked as completed.")
else:
print("Invalid task number.")
else:
print("No tasks.")
elif choice == '4':
if tasks:
idx = int(input("Enter task number to delete: ")) - 1
if 0 <= idx < len(tasks):
del tasks[idx]
print("Task deleted.")
else:
print("Invalid task number.")
else:
print("No tasks.")
elif choice == '5':
print("Exiting...")
break
else:
print("Invalid choice. Please enter a number from 1 to 5.")
if __name__ == "__main__":
print("Welcome to the To-Do List Application!")
main()