class Menu: def __init__(self): self.notebook = NoteBook() self.choices = { "1": self.show_notes, "2": self.search_notes, "3": self.add_note, "4": self.modify_note, "5": self.quit } def display_menu(self): print(""" Notebook Menu 1. Show all Notes 2. Search Notes 3. Add Note 4. Modify Note 5. Quit """) def run(self): while true: self.display_menu() choice = input("Enter an option:") action = self.choices.get(str(choice)) if action: action() else: print("{0} is not a valid choice".format(choice)) def show_notes(self, notes=None): if not notes: notes = self.notebook.notes for note in notes: print("{0}: {1}\n{2}".format(note.id, note.tags, note.memo)) def search_notes(self): ifilter = raw_input("Search for:") notes = self.notebook.search(ifilter) self.show_notes(notes) def add_note(self): memo = raw_input("Enter a memo:") print(memo) self.notebook.new_note(memo) print("Your note has been added.") def modify_note(self): note_id = raw_input("Enter a note id:") memo = raw_input("Enter a memo:") tags = raw_input("Enter tags:") if memo: self.notebook.modify_memo(note_id, memo) if tags: self.notebook.modify_tags(note_id, tags) def quit(self): sys.exit(0)
class Menu: '''Display a menu and respond to choices when run''' def __init__(self): self.notebook = NoteBook() self.choices = { "1" : self.show_notes, "2" : self.search_notes, "3" : self.add_note, "4" : self.modify_note, "5" : self.quit } def display_menu(self): print(""" Notebook Menu 1. Show all Notes 2. Search Notes 3. Add Note 4. Modify Note 5. Quit """) def run(self): """Display the menu and respond to choices""" while True: self.display_menu() choice = input("Enter an option: ") action = self.choices.get(choice) if action: action() else: print("{0} is not a valid choice", format(choice)) def show_notes(self, notes=None): if not notes: notes = self.notebook.notes for note in notes: print("{0}: {1}\n {2}". format(note.id, note.tags, note.memo)) def search_notes(self): filter = input("Search for: ") notes = self.notebook.search(filter) self.show_notes(notes) def add_note(self): memo = input("Enter a memo: ") self.notebook.new_note(memo) print("Your note has been added") def modify_note(self): if = input("Enter a note id: ") memo = input("Enter a memo; ") tags = input("Enter tags: ") if memo: self.notebook.modify_memo(id, memo) if tags: self.notebook.modify_tags(id, tags) def quit(self): print("Thank you for using your notebook today") sys.exit(0) if __name__ == '__main__': Menu().run()
class Memu(object): def __init__(self): self.notebook = NoteBook() self.choices = { "1":self.show_notes, "2":self.search_notes, "3":self.add_note, "4":self.modify_note, "5":self.quit } def display_memu(self): print (""" Notebook Menu 1.Show all Notes 2.Search Notes 3.Add Note 4.Modify Note 5.Quit """) def run(self): while True: self.display_memu() choice = raw_input("Enter an option:") action = self.choices.get(choice) if action: action() else: print "{0} is not a valid choice".format(choice) def show_notes(self,notes = None): if not notes: notes = self.notebook.notes for note in notes: print ("{0}:{1}\n{2}".format(note.id,note.tags,note.memo)) def search_notes(self): filter = raw_input("Search for:") notes = self.notebook.search(filter) self.show_notes(notes) def add_note(self): memo = raw_input("Enter a memo:") self.notebook.new_note(memo) print "Your note has been added." def modify_note(self): id = raw_input("Enter a note id:") memo = raw_input("Enter a memo:") tags = raw_input("Enter tags:") if memo: self.notebook.modify_note(id,memo) if tags: self.notebook.modify_tags(id,tags) def quit(self): print "Thank you for using your notebook today." sys.exit(0)
class Menu: """Display a menu and respond to choices when run.""" def __init__(self): self.notebook = NoteBook() self.choices = { "1": self.show_notes, "2": self.search_notes, "3": self.add_note, "4": self.modify_note, "5": self.quit, } def display_menu(self): print( """ Notebook Menu 1. Show all Notes 2. Search Notes 3. Add Note 4. Modify Note 5. Quit """) def run(self): """Display the menu and respond to choices.""" while True: self.display_menu() choice = input('Enter an option: ') action = self.choices.get(choice) if action: action() else : print(f'{choice} is not a valid option') def show_notes(self, notes=None)-> List: """displays all the notes in the notebook""" if not notes: notes = self.notebook.notes for note in notes: print(f'{note.id}: {note.tags}\n{note.memo}') def search_notes(self): """search for a note in the notebook""" filter = str(input('search for:')) note = self.notebook.search(filter) self.show_notes(note) def add_note(self): """Add a new note""" memo = str(input('Enter a memo:')) tags = str(input('Enter a tag:')) self.notebook.new_note(memo, tags) print('You have added a new note') def modify_note(self): """Modify an existing note""" id = input('Enter a note id:') memo = str(input('Enter a memo:')) tags = str(input('Enter a tag:')) if memo: self.notebook.modify_memo(id, memo) if tags: self.notebook.modify_tags(id, tags) def quit(self): print('Thank you for using the notebook today') sys.exit(0)
class Menu: def __init__(self): self.notebook = NoteBook() self.choices = { '1': self.show_notes, '2': self.search_notes, '3': self.add_notes, '4': self.modify_note, '5': self.quit } def display_menu(self): print(""" Notebook Menu 1. to show all notes 2. Search 3. ADD NEW NOTES 4. Modify 5. QUIT """) def run(self): while True: self.display_menu() choice = input('hey pick an option: ') action = self.choices.get(choice) if action: action() else: print("{0} is not a valid choice".format(choice)) def show_notes(self, notes=None): if not notes: notes = self.notebook.notes for note in notes: print("{0}: {1}\n{2}".format(note.id, note.tags.note.memo)) def search_notes(self): filter = input('sEARCH FOR: ') notes = self.notebook.search(filter) self.show_notes(notes) def add_notes(self): memo = input('Type in your memo: ') self.notebook.new_note(memo) print('Your note has been added') def modify_note(self): id = input('Enter id here: ') memo = input('Modify notes: ') tags = input('modify tags: ') if memo: self.notebook.modify_memo(id, memo) if tags: self.notebook.modify_tags(id, tags) def quit(self): print('Thank you for using my Notebook') sys.exit(0)
class Menu: """interface to the users""" def __init__(self): self.notebook = NoteBook() self.choices = {1:self.add_notes, 2:self.modify_notes_tags, 3:self.append_notes_tags, 4:self.search_notes, 5:self.display_notes, 6:self.quit} def show_menu(self): print(""" \n Menu\n-----------------------------------------------------------\n\n 1. Add notes\n 2. Modify notes or tags\n 3. Append notes or tags\n 4. Search notes\n 5. Display notes\n 6. Quit\n""") def run(self): while True: self.show_menu() choice = int(input('Please enter your choice: ')) if choice > 5 or choice < 0: print('Incorrect Choice') break else: self.choices[choice]() def add_notes(self): memo = input('Please enter your memo: ') tags = input('Please enter your tags: ') self.notebook.create_notes(memo,tags) print('Note added') def modify_notes_tags(self): id = input("Please let me know the Note id: ") if self.notebook.check_id(id): memo = input("Please let me know the updated Note memo: ") tags = input("Please let me know the updated Note tags: ") if memo: self.notebook.modify_notes_tags(id,memo) if tags: self.notebook.modify_notes_tags(id,tags) else: print('Id not available') def append_notes_tags(self): id = input("Please let me know the Note id: ") if self.notebook.check_id(id): memo = input("Please let me know the memo to be appended: ") tags = input("Please let me know the tags to be appended: ") if memo: self.notebook.append_notes_tags(id,memo) if tags: self.notebook.append_notes_tags(id,tags) else: print('Id not available') def search_notes(self): filter = input("Please enter the filter string: ") self.notebook.search(filter) def display_notes(self): self.notebook.display() def quit(self): exit()
class Menu(object): """简单的提供一个菜单接口并允许用户输入他们的选择""" def __init__(self): self.notebook = NoteBook() self.choices = { "1": self.show_notes, "2": self.search_notes, "3": self.add_note, "4": self.modify_note, "5": self.quit } def diaplay_menu(self): print(''' NoteBook Menu 1. Ahow all Notes 2. Search Notes 3. Add Note 4. Modify Note 5. Quit ''') def run(self): '''列出所有choice并调用相应的action''' while True: self.diaplay_menu() choice = input("Enter an option:") action = self.choices.get(choice) if action: action() else: print('{0} is not a valid choice'.format(choice)) def show_notes(self, notes=None): if not notes: notes = self.notebook.notes for note in notes: print("{0}: {1}\n{2}".format(note.id, note.tags, note.memo)) def search_notes(self): filter = input("Search for:") notes = self.notebook.search(filter) self.show_notes(notes) def add_note(self): memo = input("Enter a memo") self.notebook.new_note(memo) print("Your note has been added") def modify_note(self): id = input("Enter a note id") memo = input("Enter a memo") tags = input("Enter tags") if memo: self.notebook.modify_memo(id, memo) if tags: self.notebook.modify_tags(id, tags) def quit(self): print("Thank you for using your notebook today. ") sys.exit(0)