SHOW:
|
|
- or go back to the newest paste.
1 | class Task: | |
2 | def __init__(self, name): | |
3 | self.name = name | |
4 | self.completed = False | |
5 | ||
6 | def edit_name(self, new_name): | |
7 | self.name = new_name | |
8 | ||
9 | class TaskManager: | |
10 | def __init__(self): | |
11 | self.tasks = [] | |
12 | ||
13 | def add_task(self, name): | |
14 | task = Task(name) | |
15 | self.tasks.append(task) | |
16 | self.display_tasks() | |
17 | ||
18 | def remove_task(self, index): | |
19 | if 0 <= index < len(self.tasks): | |
20 | del self.tasks[index] | |
21 | self.display_tasks() | |
22 | ||
23 | def complete_task(self, index): | |
24 | if 0 <= index < len(self.tasks): | |
25 | self.tasks[index].completed = True | |
26 | self.display_tasks() | |
27 | ||
28 | def display_tasks(self): | |
29 | if len(self.tasks) == 0: | |
30 | print("\nBrak zadań.") | |
31 | else: | |
32 | print("\nLista zadań:") | |
33 | for index, task in enumerate(self.tasks): | |
34 | status = "Zakończone" if task.completed else "Niezakończone" | |
35 | print(f"{index}. {task.name} - {status}") | |
36 | ||
37 | def edit_task(self, index, new_name): | |
38 | if 0 <= index < len(self.tasks): | |
39 | self.tasks[index].edit_name(new_name) | |
40 | print("Nazwa zadania została zmieniona.") | |
41 | ||
42 | task_manager = TaskManager() | |
43 | ||
44 | while True: | |
45 | print("\n=============================\n") | |
46 | ||
47 | print("1. Dodaj nowe zadanie") | |
48 | print("2. Usuń zadanie") | |
49 | print("3. Oznacz zadanie jako zakończone") | |
50 | print("4. Wyświetl wszystkie zadania") | |
51 | print("5. Edytuj zadanie") | |
52 | print("6. Wyjdź z programu") | |
53 | ||
54 | print("\n=============================\n") | |
55 | ||
56 | choice = input("Wybierz opcję: ") | |
57 | ||
58 | if choice == "1": | |
59 | name = input("Podaj nazwę zadania: ") | |
60 | task_manager.add_task(name) | |
61 | print("Zadanie dodane.") | |
62 | ||
63 | elif choice == "2": | |
64 | index = int(input("Podaj indeks zadania do usunięcia: ")) | |
65 | if index < 0 or index >= len(task_manager.tasks): | |
66 | print("Niepoprawne dane.") | |
67 | continue | |
68 | else: | |
69 | task_manager.remove_task(index) | |
70 | print("Zadanie usunięte.") | |
71 | ||
72 | elif choice == "3": | |
73 | index = int(input("Podaj indeks zadania do oznaczenia jako zakończone: ")) | |
74 | if index < 0 or index >= len(task_manager.tasks): | |
75 | print("Niepoprawne dane.") | |
76 | continue | |
77 | else: | |
78 | task_manager.complete_task(index) | |
79 | print("Zadanie oznaczone jako zakończone.") | |
80 | ||
81 | elif choice == "4": | |
82 | task_manager.display_tasks() | |
83 | ||
84 | elif choice == "5": | |
85 | index = int(input("Podaj indeks zadania do edycji: ")) | |
86 | if index < 0 or index >= len(task_manager.tasks): | |
87 | print("Niepoprawne dane.") | |
88 | continue | |
89 | else: | |
90 | new_name = input("Podaj nową nazwę zadania: ") | |
91 | task_manager.edit_task(index, new_name) | |
92 | ||
93 | elif choice == "6": | |
94 | break | |
95 | ||
96 | ||
97 | ||
98 | else: | |
99 | print("Nieznana opcja.") |