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