Skip to content

Commit 168ca21

Browse files
committed
22-Projects
1 parent 0e30cf8 commit 168ca21

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

22-Projects/note_taking.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
3+
NOTES_FILTE=r"D:\codebhaiya\courses\python-course\22-Projects\notes.txt"
4+
# print(os.path.dirname(NOTES_FILTE))
5+
# s = " abhinay "
6+
# print(s.strip())
7+
def load_notes():
8+
if os.path.exists(NOTES_FILTE):
9+
with open(NOTES_FILTE, "r") as f:
10+
notes = f.readlines()
11+
return [note.strip() for note in notes]
12+
else:
13+
return []
14+
15+
def save_notes(notes):
16+
with open(NOTES_FILTE,"w") as f:
17+
for note in notes:
18+
f.write(note + "\n")
19+
20+
21+
def add_note():
22+
note = input("Enter your note: ")
23+
notes = load_notes()
24+
notes.append(note)
25+
save_notes(notes)
26+
print("Note added successfully.")
27+
28+
def view_notes():
29+
notes = load_notes()
30+
if notes:
31+
print("Your notes")
32+
for i, note in enumerate(notes,1):
33+
print(f"{i}. {note}")
34+
else:
35+
print("No notes found.")
36+
37+
38+
def delete_note():
39+
notes = load_notes()
40+
if notes:
41+
try:
42+
note_index = int(input("Enter note number to delete: ")) - 1
43+
if 0<= note_index < len(notes):
44+
removed_note = notes.pop(note_index)
45+
save_notes(notes)
46+
print(f"Note {removed_note} is deleted.")
47+
else:
48+
print("Please, enter valid number.")
49+
except ValueError:
50+
print("Enter valid index from (1,2,3,4)")
51+
52+
def main():
53+
while True:
54+
print("\nNote Taking App")
55+
print("1. Add Note\n2. View Notes\n3. Delete Note\n4. Exit")
56+
57+
choice = input("Enter your option (1/2/3/4): ")
58+
if choice == "1":
59+
add_note()
60+
elif choice == "2":
61+
view_notes()
62+
elif choice == "3":
63+
delete_note()
64+
elif choice=="4":
65+
print("Have a gooday, bye!")
66+
break
67+
else:
68+
print("Enter valid option")
69+
70+
if __name__ == "__main__":
71+
main()
72+
# pass

22-Projects/notes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello note

22-Projects/readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
def load_notes():
3+
pass
4+
5+
def save_notes(notes):
6+
pass
7+
8+
def add_note():
9+
pass
10+
11+
def view_notes():
12+
pass
13+
14+
def delete_note():
15+
pass
16+

0 commit comments

Comments
 (0)