Repository navigation
Expand file tree
/
Copy pathtaskmanager.py
More file actions
73 lines (65 loc) · 2.18 KB
/
Copy pathtaskmanager.py
File metadata and controls
73 lines (65 loc) · 2.18 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
70
71
72
73
class Task:
def __init__(self, task_id, title, description, status):
self.id = task_id
self.title = title
self.description = description
self.status = status
def __str__(self):
return f"[{self.id}] {self.title} - {self.description} (Status: {self.status})"
def create_task(task_list):
task_id = len(task_list) + 1
title = input("Enter task title: ")
description = input("Enter task description: ")
status = input("Enter task status (To Do, In Progress, Done): ")
task = Task(task_id, title, description, status)
task_list.append(task)
print("Task created successfully.")
def read_tasks(task_list):
if not task_list:
print("No tasks available.")
else:
for task in task_list:
print(task)
def update_task(task_list):
task_id = int(input("Enter task ID to update: "))
for task in task_list:
if task.id == task_id:
task.title = input("Enter new task title: ")
task.description = input("Enter new task description: ")
task.status = input("Enter new task status (To Do, In Progress, Done): ")
print("Task updated successfully.")
return
print("Task not found.")
def delete_task(task_list):
task_id = int(input("Enter task ID to delete: "))
for task in task_list:
if task.id == task_id:
task_list.remove(task)
print("Task deleted successfully.")
return
print("Task not found.")
def main():
task_list = []
while True:
print("\nTask Manager")
print("1. Create Task")
print("2. Read Tasks")
print("3. Update Task")
print("4. Delete Task")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == '1':
create_task(task_list)
elif choice == '2':
read_tasks(task_list)
elif choice == '3':
update_task(task_list)
elif choice == '4':
delete_task(task_list)
elif choice == '5':
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()