Post

Replies

Boosts

Views

Activity

Reply to Xcode in windows pc
import json from datetime import datetime class Task: def init(self, description, category, priority, due_date=None, completed=False): self.description = description self.category = category self.priority = priority self.due_date = due_date self.completed = completed def __str__(self): status = "✓" if self.completed else " " due_date_str = f" - Vence el {self.due_date}" if self.due_date else "" return f"[{status}] {self.description} ({self.category}, {self.priority}){due_date_str}" class ToDoList: def init(self): self.tasks = [] def add_task(self, description, category, priority, due_date=None): task = Task(description, category, priority, due_date) self.tasks.append(task) print("Tarea agregada:", description) def view_tasks(self): if self.tasks: print("Lista de tareas:") for index, task in enumerate(self.tasks, start=1): print(f"{index}. {task}") else: print("No hay tareas en la lista.") def toggle_task(self, index): if 1 <= index <= len(self.tasks): task = self.tasks[index - 1] task.completed = not task.completed print("Estado de tarea cambiado:", task.description) else: print("Índice de tarea no válido.") def remove_task(self, index): if 1 <= index <= len(self.tasks): removed_task = self.tasks.pop(index - 1) print("Tarea eliminada:", removed_task.description) else: print("Índice de tarea no válido.") def save_tasks(self, filename): task_data = [{ "description": task.description, "category": task.category, "priority": task.priority, "due_date": task.due_date, "completed": task.completed } for task in self.tasks] with open(filename, "w") as file: json.dump(task_data, file) def load_tasks(self, filename): try: with open(filename, "r") as file: task_data = json.load(file) self.tasks = [Task( task_info["description"], task_info["category"], task_info["priority"], task_info["due_date"], task_info["completed"] ) for task_info in task_data] except FileNotFoundError: pass def main(): todo_list = ToDoList() todo_list.load_tasks("tasks.json") while True: print("\n1. Agregar tarea") print("2. Ver tareas") print("3. Cambiar estado de tarea") print("4. Eliminar tarea") print("5. Guardar tareas") print("6. Salir") choice = input("Seleccione una opción: ") if choice == "1": task_description = input("Ingrese la descripción de la tarea: ") task_category = input("Ingrese la categoría de la tarea: ") task_priority = input("Ingrese la prioridad de la tarea (Alta/Media/Baja): ") due_date_str = input("Ingrese la fecha de vencimiento (opcional - formato: AAAA-MM-DD): ") due_date = datetime.strptime(due_date_str, "%Y-%m-%d") if due_date_str else None todo_list.add_task(task_description, task_category, task_priority, due_date) elif choice == "2": todo_list.view_tasks() elif choice == "3": todo_list.view_tasks() task_index = int(input("Ingrese el número de la tarea para cambiar su estado: ")) todo_list.toggle_task(task_index) elif choice == "4": todo_list.view_tasks() task_index = int(input("Ingrese el número de la tarea para eliminar: ")) todo_list.remove_task(task_index) elif choice == "5": todo_list.save_tasks("tasks.json") print("Tareas guardadas.") elif choice == "6": print("¡Hasta luego!") break else: print("Opción no válida. Intente nuevamente.") if name == "main": main()
Aug ’23