-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodos.py
50 lines (40 loc) · 1.12 KB
/
todos.py
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
import json
file_name = "t2.json"
with open(file_name, "r") as handle:
data = json.load(handle)
todos = ["pet the cat", "go to work", "shop for groceries", "go home", "feed the cat"]
def print_todo():
print('------- Todos -------')
count=1
for todo in todos:
print(f'{count}: {todo}')
count += 1
print('--------------------')
with open(file_name, "w") as handle:
data = json.load(handle)
while True:
print("""
Choose and option:
1. Print Todo
2. Add Todo
3. Remove Todo
0. Quit
""")
user_choice = input('')
if user_choice == '1':
# print current todos
print_todo()
elif user_choice == '2':
#add a new item
new_item = input('What do you want to add? ')
todos.append(new_item)
elif user_choice == '3':
#delete a todo
print_todo()
#ask user which item to delete
delete_index = int(input('Which item would you like to delete? '))
#delete item from list by user provided index
del todos[delete_index -1]
elif user_choice == '0':
#exit program
break