Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Use r programming Write a function that returns (pi)r^2

Answered: 1 week ago

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago