import sys # Simple Todo Application class TodoApp: def __init__(self): self.todos = [] # List to store todo items, each as a dict {'task': str, 'completed': bool} def add_task(self, task): """Add a new task to the todo list.""" if task: self.todos.append({'task': task, 'completed': False}) print(f"Added task: {task}") else: print("Task cannot be empty.") def delete_task(self, index): """Delete a task by its index.""" if 0 <= index < len(self.todos): deleted = self.todos.pop(index) print(f"Deleted task: {deleted['task']}") else: print("Invalid task index.") def mark_complete(self, index): """Mark a task as complete by its index.""" if 0 <= index < len(self.todos): self.todos[index]['completed'] = True print(f"Marked as complete: {self.todos[index]['task']}") else: print("Invalid task index.") def list_tasks(self): """List all tasks with their status.""" if not self.todos: print("No tasks available.") for i, todo in enumerate(self.todos): status = "Completed" if todo['completed'] else "Pending" print(f"{i + 1}. {todo['task']} - {status}") def run(self): """Run the todo application in a loop.""" while True: print("\nTodo App Menu:") print("1. Add Task") print("2. Delete Task") print("3. Mark Task as Complete") print("4. List Tasks") print("5. Quit") choice = input("Enter your choice (1-5): ").strip() if choice == '1': task = input("Enter task: ").strip() self.add_task(task) elif choice == '2': self.list_tasks() try: index = int(input("Enter task number to delete: ")) - 1 self.delete_task(index) except ValueError: print("Invalid input. Please enter a number.") elif choice == '3': self.list_tasks() try: index = int(input("Enter task number to mark complete: ")) - 1 self.mark_complete(index) except ValueError: print("Invalid input. Please enter a number.") elif choice == '4': self.list_tasks() elif choice == '5': print("Exiting Todo App.") sys.exit(0) else: print("Invalid choice. Please try again.") if __name__ == "__main__": app = TodoApp() app.run()