forked from kamilbrzezinski/python-5-projektow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-praktyka.py
More file actions
75 lines (52 loc) · 1.41 KB
/
15-praktyka.py
File metadata and controls
75 lines (52 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
user_choice = -1
tasks = []
def show_tasks():
task_index = 0
for task in tasks:
print(task + " [" + str(task_index) + "]")
task_index += 1
def add_task():
task = input("Wpisz treść zadania: ")
if task == "0":
print("Powrót do menu")
else:
tasks.append(task)
print("Dodano zadanie!")
def delete_task():
task_index = int(input("Podaj indeks zadania do usunięcia: "))
if task_index < 0 or task_index > len(tasks) - 1:
print("Zadanie o tym indeksie nie istnieje")
return
tasks.pop(task_index)
print("Usunięto zadanie!")
def save_tasks_to_file():
file = open("tasks.txt", "w")
for task in tasks:
file.write(task+"\n")
file.close()
def load_tasks_from_file():
try:
file = open("tasks.txt")
for line in file.readlines():
tasks.append(line.strip())
file.close()
except FileNotFoundError:
return
load_tasks_from_file()
while user_choice != 5:
if user_choice == 1:
show_tasks()
if user_choice == 2:
add_task()
if user_choice == 3:
delete_task()
if user_choice == 4:
save_tasks_to_file()
print()
print("1. Pokaż zadania")
print("2. Dodaj zadanie")
print("3. Usuń zadanie")
print("4. Zapisz zmiany do pliku")
print("5. Wyjdź")
user_choice = int(input("Wybierz liczbę: "))
print()