forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise08.py
More file actions
31 lines (27 loc) · 850 Bytes
/
exercise08.py
File metadata and controls
31 lines (27 loc) · 850 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
29
30
31
import json
try:
with open("reminders.json") as f:
reminders = json.load(f)
except FileNotFoundError:
reminders = []
while True:
print("1-add reminder")
print("2-remove reminder")
print("3-print reminders")
print("4-exit")
choice = int(input("Pick one: "))
if choice==1:
reminder = input("New reminder: ")
reminders.append(reminder)
with open("reminders.json", "w") as f:
json.dump(reminders, f)
elif choice==2:
reminder_index = int(input("Give index of the reminder: "))
reminders.pop(reminder_index)
with open("reminders.json", "w") as f:
json.dump(reminders, f)
elif choice==3:
for i in range(len(reminders)):
print(f"{i}. {reminders[i]}")
elif choice==4:
break