-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.py
More file actions
57 lines (47 loc) · 1.3 KB
/
todo.py
File metadata and controls
57 lines (47 loc) · 1.3 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
import json
todoList = []
try:
with open ('todofile', 'r') as todofile:
todoList = json.load(todofile)
except FileNotFoundError:
pass
def display():
for index, todo in enumerate(todoList):
print(
index+1, "\t",
"[*]" if todo["done"] else "[ ]",
todo["task"]
)
while True:
# print Menu
print("Menu:")
print("1. Create Todo")
print("2. View Todo List")
print("3. Mark Todo as Complete")
print("4. Delete Todo")
print("0. Exit")
option = input("Enter the option number: ")
if option == "1": # create
todo = {"done":False, "task" :input("Enter task: ")}
todoList.append(todo)
elif option == "2": # Display
display()
pass
elif option == "3": # Mark as Complete
index = int(input("Enter index of completed todo: "))
todoList[index-1]["done"] = True
display()
pass
elif option == "4": # Delete
display()
index = int(input("Index to delete: "))
index -= 1
todoList.pop (index)
# todoList[index:index+1] = []
pass
elif option == "0": # exit
break
else:
print("No such option")
with open ('todofile', 'w') as todofile:
json.dump(todoList, todofile)