Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (58 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
69 lines (58 loc) · 1.42 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
#todo list
import os
a = True
lista = []
PLIK = "todo.txt"
def dodaj():
tresc = input("Co chciałbyś dodać do listy")
lista.append(tresc)
zapisz()
def usun():
wyswietl()
if not lista:
print("Nie ma jeszcze nic na liście")
return
else:
try:
numer = int(input("Które chcesz usunąć"))
except ValueError:
print("Musisz podać liczbe")
return
if 0 < numer <= len(lista):
lista.pop(numer - 1)
zapisz()
else: print("Nie ma takiego zadania")
def wyswietl():
if not lista:
print("Nie ma żadnych zadań")
else:
for index, item in enumerate(lista):
print(f"{index + 1}.{item}")
def zapisz():
with open(PLIK, "w") as f:
for item in lista:
f.write(item + "\n")
if os.path.exists(PLIK):
with open(PLIK, "r") as f:
lista = [line.strip() for line in f.readlines()]
while a:
print("Lista Zadań")
print("1.Wyświetl")
print("2.Dodaj")
print("3.Usuń")
print("4.Wyjście")
try:
pytanie = int(input("Co chciałbyś zrobić: "))
except ValueError:
print("Musisz podać liczbę")
continue
if pytanie == 1:
wyswietl()
elif pytanie == 2:
dodaj()
elif pytanie == 3:
usun()
elif pytanie == 4:
a = False
else:
print("Nie ma takiej funkcji")