-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.py
More file actions
56 lines (49 loc) · 1.38 KB
/
Copy pathtodo.py
File metadata and controls
56 lines (49 loc) · 1.38 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
FILE_NAME = "tasks.txt"
def load_tasks():
tasks = []
try:
with open(FILE_NAME, "r") as f:
for line in f:
task, status = line.strip().split("|")
tasks.append({"task": task, "done": status == "1"})
except FileNotFoundError:
pass
return tasks
def save_tasks(tasks):
with open(FILE_NAME, "w") as f:
for t in tasks:
f.write(f"{t['task']}|{int(t['done'])}\n")
def show_tasks(tasks):
if not tasks:
print("No tasks available")
return
for i, t in enumerate(tasks, 1):
status = "✔" if t["done"] else "✗"
print(f"{i}. {t['task']} [{status}]")
def add_task(tasks):
task = input("Enter task: ")
tasks.append({"task": task, "done": False})
def mark_done(tasks):
show_tasks(tasks)
try:
idx = int(input("Task number to mark done: ")) - 1
tasks[idx]["done"] = True
except:
print("Invalid input")
def main():
tasks = load_tasks()
while True:
print("\n1.Add 2.View 3.Done 4.Exit")
choice = input("Choose: ")
if choice == "1":
add_task(tasks)
elif choice == "2":
show_tasks(tasks)
elif choice == "3":
mark_done(tasks)
elif choice == "4":
save_tasks(tasks)
break
else:
print("Invalid choice")
main()