-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto_do_list.py
More file actions
87 lines (69 loc) · 2.35 KB
/
to_do_list.py
File metadata and controls
87 lines (69 loc) · 2.35 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
#create an empty list to store the tasks and their status
todo_list = []
#function to add task
def add_task():
task = input("Enter the task: ")
todo_list.append({"Task": task, "Status": "pending"})
print(1)
print("New task added sucessfully\n")
#Function to view task
def view_task():
print("Your to-do list: ")
if len(todo_list) == 0:
print("No pending task")
else:
for index, task in enumerate(todo_list, 1):
print(f"{index}: {task['Task']} - {task['Status']}")
print('\n')
#function to remove the task via index
def remove_task():
if len(todo_list) == 0:
print("\n List is empty")
else:
try:
search_index = int(input("Enter the task number that want to be removed: ")) - 1
if 0 <= search_index < len(todo_list):
removed_task = todo_list.pop(search_index)
print(f"Task removed is: {removed_task['Task']}")
else:
print("Invalid Task number")
except ValueError:
print("Please enter valid Task number")
#Function to mark task done
def mark_done():
if len(todo_list) == 0:
print("List is empty")
else:
try:
search_index = int(input("Enter the task number that want to be marked done: ")) - 1
if 0 <= search_index < len(todo_list):
todo_list[search_index]['Status'] = 'done'
print(f"Task {todo_list[search_index]['Task']} has been marked as Done")
else:
print("Invalid Task number")
except ValueError:
print("Please enter valid Task number")
#function to display a menu
def menu():
while(True):
print("***MAIN MENU***")
print("1. Add a new Task")
print("2. View all Tasks")
print("3. Remove a Task")
print("4. Mark the task completed")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == "1":
add_task()
elif choice == "2":
view_task()
elif choice == "3":
remove_task()
elif choice == "4":
mark_done()
elif choice == "5":
print("Exiting the application")
exit()
else:
print("Inavlid input and try again")
menu()