forked from werhereitacademy/Python_Modul_Week_3
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask_manager.py
More file actions
132 lines (99 loc) · 3.72 KB
/
task_manager.py
File metadata and controls
132 lines (99 loc) · 3.72 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Id_tracking=[]
tasks = [
{"sequence_number": 1, "task_name": "Task 1", "status": "Pending"},
{"sequence_number": 2, "task_name": "Task 2", "status": "Completed"},
{"sequence_number": 3, "task_name": "Task 3", "status": "Pending"},
]
#MR E
def add_task():
Id_tracking.sort()
task=input("Please enter the task:")
if len(Id_tracking)==0:
id_temp=len([x for x in tasks if x["status"]!="Deleted"])+1
tasks.append({"sequence_number":id_temp,"task_name":task,"status":"pending"})
else:
tasks.append({"sequence_number":Id_tracking[0],"task_name":task,"status":"pending"})
Id_tracking.pop(0)
tasks.sort(key=lambda x: (x['sequence_number'] is None, x['sequence_number']))
print (f'"{task}" is added')
#Mrs I
def list_completed_tasks():
completed_tasks = list(filter(lambda task: task["status"] == "Completed", tasks))
if completed_tasks:
print("Completed Tasks:")
for task in completed_tasks:
print( f'ID number:{task["sequence_number"]}-{task["task_name"]}')
else:
print("No completed tasks found!")
#Mrs I
def list_all_tasks():
all_tasks = list(filter(lambda tasks: tasks["status"] != "Deleted", tasks))
if all_tasks:
print("---All Tasks---")
for task in all_tasks:
print(task["sequence_number"], "-", task["task_name"], "Status:",task["status"])
else:
print("No tasks found!")
#Mrs E
def compleet_a_task():
if tasks:
user=int(input("Please enter an ID number: "))
task_control=False
for task in tasks:
if task['sequence_number']==user:
if task["status"]=="Completed":
print("It is already completed")
task_control=True
if task["status"]=="Pending":
task["status"]="Completed"
task_control=True
print(f'Task "{task["task_name"]}" is completed')
if not task_control:
print("Id is not found")
else:
print("There is no task")
# Mr N
def delete_task():
"""Delete a task from the system."""
if tasks:
try:
sequence_number = int(input("Enter the ID number of the task to delete: "))
for task in tasks:
if task["sequence_number"] == sequence_number:
confirm = input(f"Are you sure you want to delete the task '{task['task_name']}'? (Y/N): ").strip().upper()
if confirm == "Y":
task["status"] = "Deleted"
Id_tracking.append(sequence_number)
task["sequence_number"]=None
print(f"Task deleted successfully: {task['task_name']}")
elif confirm == "N":
print("Task deletion canceled.")
else:
print("Invalid choice. Task deletion canceled.")
return
print("Task is not found")
except ValueError:
print("Invalid input. Please enter a number.")
else:
print("There is no task")
while True:
print("\n\n1-Add task")
print("2-Delete task")
print("3-List all completed task")
print("4-List all tasks")
print("5-Complete the task")
print("6-Logout\n\n")
chs=int(input("Please enter your choice:"))
if chs==1:
add_task()
elif chs==2:
delete_task()
elif chs==3:
list_completed_tasks()
elif chs==4:
list_all_tasks()
elif chs==5:
compleet_a_task()
else:
print("You are logged out")
break