Question: import os import pickle import subprocess class AlwaysNote: def _ _ init _ _ ( self ) : self.notes = [ ] self.filename = notes.pkl

import os
import pickle
import subprocess
class AlwaysNote:
def __init__(self):
self.notes =[]
self.filename = "notes.pkl"
self.load_notes()
def clear_screen(self):
subprocess.call('cls' if os.name =='nt' else 'clear', shell=True)
def display_menu(self):
print(".: ALWAYSNOTE :.")
print("-- gold edition --")
print("******************")
self.display_notes_titles()
print("------------------")
print("view | view note")
print("add | add note")
print("rm | remove note")
print("exit | exit program")
print("------------------")
def display_notes_titles(self):
for note in self.notes:
print(f"-{note['title']}")
def view_note(self, title):
self.clear_screen()
for note in self.notes:
if note['title']== title:
print(f"
{note['title']}")
print("------------------")
input("Press enter to continue...")
print(f"
Description: {note['description']}
")
input("Press Enter to continue...")
break
else:
print("----------------------")
print(f"
ERROR: Unknown note
")
print("---------------------")
input("Press Enter to continue...")
def add_note(self, title, description):
self.notes.append({'title': title, 'description': description})
print("--------------------------")
print("
INFO: Note added!
")
input("Press Enter to continue...")
def remove_note(self, title):
for note in self.notes:
if note['title']== title:
self.notes.remove(note)
print("
INFO: Note deleted successfully
")
print("---------------------")
input("Press Enter to continue...")
break
else:
print("----------------------")
print("
ERROR: Unknown note
")
print("-----------------------")
input("Press Enter to continue...")
def save_notes(self):
with open(self.filename, 'wb') as file:
pickle.dump(self.notes, file)
def load_notes(self):
if os.path.exists(self.filename):
with open(self.filename, 'rb') as file:
self.notes = pickle.load(file)
def run(self):
while True:
self.clear_screen() # Move clear_screen outside the loop
self.display_menu()
choice = input("menu >").lower()
print("----------------------")
if choice == 'view':
title = input("title >")
self.view_note(title)
elif choice == 'add':
title = input("title >")
description = input("descr >")
self.add_note(title, description)
elif choice =='rm':
title = input("title >")
self.remove_note(title)
elif choice == 'exit':
self.save_notes()
print("Exiting program. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__=="__main__":
always_note_app = AlwaysNote()
always_note_app.run(), the menu must print only once after each operation. Do not change anything else.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!