-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (41 loc) · 1.2 KB
/
main.py
File metadata and controls
48 lines (41 loc) · 1.2 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
import json
import os
FILE = "tasks.json"
def load_tasks():
if os.path.exists(FILE):
with open(FILE, "r") as f:
return json.load(f)
return []
def save_tasks(tasks):
with open(FILE, "w") as f:
json.dump(tasks, f)
def show_tasks(tasks):
if not tasks:
print("No tasks yet!")
else:
for i, t in enumerate(tasks, start=1):
status = "✔" if t["done"] else "✗"
print(f"{i}. {t['task']} [{status}]")
def main():
tasks = load_tasks()
while True:
print("\n1. Add task\n2. View tasks\n3. Mark done\n4. Exit")
choice = input("Choose: ")
if choice == "1":
task = input("Enter task: ")
tasks.append({"task": task, "done": False})
save_tasks(tasks)
elif choice == "2":
show_tasks(tasks)
elif choice == "3":
show_tasks(tasks)
num = int(input("Task number to mark done: ")) - 1
if 0 <= num < len(tasks):
tasks[num]["done"] = True
save_tasks(tasks)
elif choice == "4":
break
else:
print("Invalid choice!")
if __name__ == "__main__":
main()