forked from mustafagundogdu80/Python_VIT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkahraman.py
More file actions
28 lines (21 loc) · 684 Bytes
/
kahraman.py
File metadata and controls
28 lines (21 loc) · 684 Bytes
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
def delete_task(tasks, task_id, tasks_file):
task_found = False
for task in tasks:
if task.get("id") == task_id:
task_found = True
task["status"] = "Deleted"
task["id"] = None
break
if not task_found:
print("Task not found")
return False
for task in tasks:
if task.get("id") and task["id"] > task_id:
task["id"] -= 1
save_file(tasks_file, tasks)
print(f"Task with ID {task_id} has been successfully deleted.")
return True
def save_file(filename, tasks):
with open(filename, "w") as file:
import json
json.dump(tasks, file, indent=4)