forked from werhereitacademy/Python_Modul_Week_3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_mamger
More file actions
82 lines (72 loc) · 2.36 KB
/
task_mamger
File metadata and controls
82 lines (72 loc) · 2.36 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
# List to hold tasks
tasks = []
next_number = 1
# Function to add a new task
def add_task():
global next_number
name = input("Enter the task name: ")
# Check for any task marked as 'removed' to reuse the slot
for t in tasks:
if t['status'] == 'Removed':
t['name'] = name
t['status'] = 'Not Done'
print("Task added at slot", t['number'])
return
# Add a new task if no 'removed' tasks
tasks.append({'number': next_number, 'name': name, 'status': 'Not Done'})
print("Task added with number", next_number)
next_number += 1
# Function to mark a task as finished
def finish_task():
num = int(input("Enter task number to mark as finished: "))
for t in tasks:
if t['number'] == num and t['status'] == 'Not Done':
t['status'] = 'Completed'
print("Task", num, "is now completed.")
return
print("Task not found or already completed.")
# Function to remove a task
def remove_task():
num = int(input("Enter task number to remove: "))
for t in tasks:
if t['number'] == num and t['status'] != 'Removed':
t['status'] = 'Removed'
print("Task", num, "has been removed.")
return
print("Task not found or already removed.")
# Function to display completed tasks
def show_completed_tasks():
print("\nCompleted Tasks:")
for t in tasks:
if t['status'] == 'Completed':
print(t['number'], t['name'])
# Function to display all tasks
def show_all_tasks():
print("\nAll Tasks:")
for t in tasks:
print(t['number'], t['name'], "-", t['status'])
# Main loop for user interaction
while True:
print("\nChoose an option:")
print("1- Add Task")
print("2- Finish Task")
print("3- Remove Task")
print("4- Show Completed Tasks")
print("5- Show All Tasks")
print("6- Exit")
choice = input("Enter your choice: ")
if choice == '1':
add_task()
elif choice == '2':
finish_task()
elif choice == '3':
remove_task()
elif choice == '4':
show_completed_tasks()
elif choice == '5':
show_all_tasks()
elif choice == '6':
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")