-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010-note_taking.py
More file actions
executable file
·64 lines (53 loc) · 1.55 KB
/
010-note_taking.py
File metadata and controls
executable file
·64 lines (53 loc) · 1.55 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
#Note taking app
#Step 1: Define the file name
FILE_NAME = "myNotex.text"
#Step 2: Display menu options
def show_menu():
print("\n---Note Taking App Menu---")
print("1. Add new note")
print("2. View all notes")
print("3. Delete all the notes")
print("4. Exit")
#Step 3: Add a new note function
def add_note():
note = input("Enter your note: ")
with open(FILE_NAME, "a") as file:
file.write(note + "\n")
print("Note added successfully!")
#Step 4: View all the notes
def view_notes():
try:
with open(FILE_NAME, "r") as file:
content = file.read()
if content:
print("\n---Your Notes---")
print(content)
else:
print("\nNo notes found.")
except FileNotFoundError:
print("No notes found.")
#Step 5: Delete all the notes
def delete_notes():
confirm = input("Are you sure you want to delete all notes? (Yes/n)")
if confirm.lower() == "yes":
with open(FILE_NAME, "w") as file:
pass
print("All notes have been deleted")
else:
print("Deletion cancelled.")
#Step 6: Main program loop
while True:
show_menu()
choice = input("Enter your choice (1-4): ")
if choice == "1":
add_note()
elif choice == "2":
view_notes()
elif choice == "3":
delete_notes()
elif choice == "4":
print("Exiting Note Taking App, Goodbye!")
break
else:
print("Invalid choice. Please enter a number between 1 and 4.")