From fad5c6fe0c8d53d1c192b6087a6da0e2118a3182 Mon Sep 17 00:00:00 2001 From: s490103 Date: Sat, 22 Jun 2024 18:01:04 +0200 Subject: [PATCH] Add proj --- proj | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 proj diff --git a/proj b/proj new file mode 100644 index 0000000..439f981 --- /dev/null +++ b/proj @@ -0,0 +1,83 @@ +import psycopg2 +import threading as th +conn = psycopg2.connect(database="dbad_s490103", + host="psql.wmi.amu.edu.pl", + user="dbad_s490103", + password="agiesticancoadi") + +cursor = conn.cursor() +cursor.execute("select * from tresc") #programowanie deklaratywne + + +data = cursor.fetchall()[0] + +conn.close() + +sens_zdanie = lambda x: " ".join(x[:-1]) + x[-1] #funkcja lambda + +lista = [] + +class zadanie: #programowanie obiektowe + def __init__(self, tresc): + self.tresc = tresc + +program_on = True + +def instrukcje(p): + print(sens_zdanie(p)) + print('Aby usunąć zadanie, wpisz "usun". \nAby dodać zadanie, wpisz "dodaj". \nAby zakończyć działanie program, wpisz "stop"') + +def ozdobniki(): + print("="*46) + +print() +if __name__ == "__main__": #multithreading + t1 = th.Thread(target=ozdobniki, args=()) + t2 = th.Thread(target=instrukcje, args=(data,)) + t3 = th.Thread(target=ozdobniki, args=()) + + t1.start() + t2.start() + t3.start() + + t1.join() + t2.join() + t3.join() + + +while program_on: + print() + print("========= TWOJA LISTA =========") + for i in lista: + print(f'{i[0]}. {i[1].tresc}') + print() + wybor = input().lower() + match wybor: + case "dodaj": + tekst = input().strip() + zadanie_do_dodania = zadanie(tekst) + if len(lista) == 0: + lista.append([1, zadanie_do_dodania]) + else: + lista.append([lista[-1][0]+1, zadanie_do_dodania]) + + case "usun": + numer = input() + try: + numer = int(numer) + if numer > len(lista): + print("Nie ma zadania o takim numerze!") + else: + lista.remove(lista[numer-1]) + for i in range(numer-1, len(lista)): + lista[i][0]-=1 + except: + print("Musisz wprowadzić numer.") + + case "stop": + break + + case _: + print("Wprowadź prawidłową komendę.") + +