From d79999d26aa7bcc2daddbdf39b8652b782ce0e8c Mon Sep 17 00:00:00 2001 From: MasterAirscrachDev Date: Fri, 11 Oct 2024 10:22:00 +0800 Subject: [PATCH] it was probably better before --- mvc/mvc_air/model.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 mvc/mvc_air/model.py diff --git a/mvc/mvc_air/model.py b/mvc/mvc_air/model.py new file mode 100644 index 0000000..d9a5b29 --- /dev/null +++ b/mvc/mvc_air/model.py @@ -0,0 +1,48 @@ +class View: + def show_menu(self): + print("\nTo-Do List Menu:\n1. Add Task\n2. List Tasks\n3. Exit") + def get_choice(self): + return input("Choose an option: ") + def get_task(self): + return input("Enter a new task: ") + def show_tasks(self, tasks): + print("\nYour Tasks:") + for idx, task in enumerate(tasks, start=1): + print(f"{idx}. {task}") + def show_message(self, message): + print(message) +#============================================================================== +class Controller: + def __init__(self, view, model): + self.view = view + self.model = model + def run(self): + while True: + self.view.show_menu() + choice = self.view.get_choice() + if choice == '1': + task = self.view.get_task() + self.model.add_task(task) + self.view.show_message("Task added!") + elif choice == '2': + tasks = self.model.list_tasks() + self.view.show_tasks(tasks) + elif choice == '3': + self.view.show_message("Goodbye!") + break + else: + self.view.show_message("Invalid option. Try again.") +#============================================================================== +class Model: + def __init__(self): + self.tasks = [] + def add_task(self, task): + self.tasks.append(task) + def list_tasks(self): + return self.tasks +#============================================================================== +if __name__ == "__main__": + view = View() + model = Model() + controller = Controller(view, model) + controller.run() \ No newline at end of file