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 ("\n Note Taking App" )
55+ print ("1. Add Note\n 2. View Notes\n 3. Delete Note\n 4. 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
0 commit comments