1+ # ------------------------------------------------------------/
2+ # ------------------------------------------------------------/
3+ # Combining it into one CLI Program
4+ print ('|-----------------------------------------|' )
5+
6+ # Function to take 'user_choice' as a input
7+ def user_choices ():
8+ print ('|-----------------------------------------|' )
9+ print ("📚 MY NOTES APP\n " )
10+ print ("Press 1: Adding New Notes!" )
11+ print ("Press 2: Viewing Notes!" )
12+ print ("Press 3: Clear Notes!" )
13+
14+ # input 'user_choice' with error handling block
15+ try :
16+ user_choice = int (input ())
17+ except TypeError as e :
18+ print ("Something went wrong!\n Error: {}" .format (e ))
19+
20+ return user_choice
21+
22+ # Function to ask user to (Continue/Exit)
23+ def process_termination ():
24+ terminate_process = input ("Continue Adding New Notes? (y/n)" ).lower ()
25+ if terminate_process in ['n' , 'no' ]:
26+ print ("Exiting The app...\n \n " )
27+ return True
28+ else :
29+ return False
30+
31+
32+ # Function to adding new notes
33+ def add_notes ():
34+ # Creating loop untill user want to exit
35+ while True :
36+ # Taking input notes from user
37+ notes_contents = input ("Start typing to add new notes...\n REMEMBER: Add single line at a time!\n " )
38+
39+ # Appending notes to a file
40+ with open ('my_simple_notes_app_file.txt' , 'a' ) as file :
41+ file .write (notes_contents + '\n ' )
42+ print ("Your notes saved successfully!\n \n " )
43+
44+ if process_termination :
45+ break
46+
47+ # Function to view & read notes
48+ def read_notes ():
49+ # Reading from file
50+ with open ('my_simple_notes_app_file.txt' , 'r' ) as file :
51+ reading_notes = file .read ()
52+ if len (reading_notes .strip ()) != 0 :
53+ print ('|-----------------------------------------|' )
54+ print ('|📚📚📚📚📚📚📚📚📚📚📚📚📚📚|' )
55+ print ("Your Notes:\n " , reading_notes )
56+ else :
57+ print ("Error! Notes empty already...\n " )
58+
59+ # Function to clear notes
60+ def clear_notes ():
61+
62+ clear_status = None
63+ while True :
64+ clear_status = input ("Are you sure to clear the notes? (y/n): " ).lower ()
65+ if clear_status not in ['y' , 'yes' , 'n' , 'no' ]:
66+ print ("Error: Incorrect input! Please try again...\n " )
67+ else :
68+ break
69+
70+ if clear_status == 'y' or clear_status == 'yes' :
71+ # check whether notes not empty already
72+ with open ('my_simple_notes_app_file.txt' , 'r' ) as file :
73+ saved_notes = file .read ()
74+ if len (saved_notes .strip ()) != 0 :
75+ # If not empty, write mode will auto clear the contents
76+ with open ('my_simple_notes_app_file.txt' , 'w' ) as file :
77+ print ("Your notes has been cleared successfully!\n " )
78+ else :
79+ print ("Error! Notes empty already...\n " )
80+ else :
81+ print ("Your notes are still safe" )
82+ print ('|-----------------------------------------|' )
83+
84+ # Function to ask to user to (Continue/Exit)
85+ def main_menu ():
86+ user_menu_choice = input ("Got to Main Menu? (y/n)" ).lower ()
87+ if user_menu_choice in ['n' , 'no' , 'nope' ]:
88+ print ("Exiting the app..." )
89+ print ('|-----------------------------------------|' )
90+ return True
91+
92+ def main ():
93+ while True :
94+ user_choice = user_choices ()
95+ if user_choice == 1 :
96+ add_notes ()
97+ elif user_choice == 2 :
98+ read_notes ()
99+ elif user_choice == 3 :
100+ clear_notes ()
101+ else :
102+ print ("Incorrect input! Please try again..." )
103+
104+ if main_menu ():
105+ break
106+
107+
108+
109+ if __name__ == "__main__" : # Checks if this script is being run directly (not imported as a module)
110+ main () # Calls the main() function to start the Notes App
0 commit comments