-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_functions.py
More file actions
68 lines (54 loc) · 1.74 KB
/
delete_functions.py
File metadata and controls
68 lines (54 loc) · 1.74 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
from os import system
from prompts import *
from main_functions import to_do_list
from add_functions import width
def delete_task():
if no_tasks(): return
system('clear')
print(delete_header)
list_valid_tasks()
delete_item = validate_task(delete_prompt, delete_header)
confirm = confirm_deletion(delete_item[0])
process_deletion(confirm, delete_item[1])
def process_deletion(confirm, index):
system('clear')
if confirm == "y":
del to_do_list[index]
print("TASK DELETED!\n".center(width))
else:
print("DELETE ACTION CANCELLED\n".center(width))
def no_tasks():
if len(to_do_list) == 0:
system('clear')
return True
def validate_task(prompt, header):
name = input(prompt)
task_index = valid_task(name.capitalize())
while task_index == -1:
system('clear')
print(header)
print("\tTask does not exist.\n")
list_valid_tasks()
name = input(prompt)
task_index = valid_task(name.capitalize())
return name.capitalize(), task_index
def valid_task(name):
for i in range(len(to_do_list)):
if to_do_list[i]["Task"] == name:
return i
return -1
def list_valid_tasks():
"""
Displays list of current tasks on To-Do List in alphabetical order
"""
print("\tCurrent tasks:")
to_do_list.sort(key = lambda x: x['Task'])
for task in to_do_list:
print("\t " + task['Task'])
print()
def confirm_deletion(task):
delete = input(f'\tAre you sure you want to delete "{task}"? (y/n) ')
while delete != "y" and delete != "n":
print("\n\tPlease press 'y' for yes or 'n' for no.")
delete = input(f'\tAre you sure you want to delete "{task}"? ')
return delete