-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmylittleNotebook.py
35 lines (31 loc) · 928 Bytes
/
mylittleNotebook.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
import datetime
import json
def create_note():
"""Create a new note and save to file"""
note = input("Enter your note: ")
time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
data = {"time": time, "note": note}
with open("notes.json", "a") as file:
json.dump(data, file)
file.write("\n")
print("Note saved successfully!")
def view_notes():
"""View all saved notes"""
with open("notes.json", "r") as file:
for line in file:
data = json.loads(line)
print(f"{data['time']}: {data['note']}")
while True:
print("\nMenu:")
print("1. Create a new note")
print("2. View saved notes")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == "1":
create_note()
elif choice == "2":
view_notes()
elif choice == "3":
break
else:
print("Invalid choice. Try again.")