mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-09-07 12:10:40 +02:00
python rzeczy
This commit is contained in:
35
uczelnia/2_semestr/python/laby/8/baza.py
Normal file
35
uczelnia/2_semestr/python/laby/8/baza.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from osoba import Osoba
|
||||
from pracownik import Pracownik
|
||||
|
||||
if __name__ == "__main__":
|
||||
baza: set[Pracownik | Osoba] = set()
|
||||
|
||||
baza.add(Osoba("2342348", "Bogdan", "Wojciechowski", 67.67, 69.69))
|
||||
baza.add(Osoba("2983473", "Stanisław", "Pięta", 123.21, 543.23))
|
||||
baza.add(Osoba("2389412", "Stefan", "Cichnicki", 67.67, 233.1))
|
||||
baza.add(Osoba("2983473", "Genowefa", "Pięta", 123.21, 543.23))
|
||||
baza.add(Osoba("2389412", "Aniela", "Głąb", 2384.1, 233.1))
|
||||
|
||||
baza.add(
|
||||
Pracownik(
|
||||
"2389412",
|
||||
"Stanisław",
|
||||
"Lem",
|
||||
"Wydawnictwo niezwykłe",
|
||||
2384.1,
|
||||
233.1,
|
||||
234123,
|
||||
)
|
||||
)
|
||||
|
||||
baza.add(
|
||||
Pracownik("2389412", "Andrzej", "Sapkowski", "CD PROJEKT RED", 2384.1, 233.1, 5)
|
||||
)
|
||||
baza.add(
|
||||
Pracownik(
|
||||
"2389412", "Andrzej", "Duda", "Pałac prezydencki", 2384.1, 233.1, 234123
|
||||
)
|
||||
)
|
||||
|
||||
for element in baza:
|
||||
print(element.__repr__())
|
||||
81
uczelnia/2_semestr/python/laby/8/figury.py
Normal file
81
uczelnia/2_semestr/python/laby/8/figury.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from math import pi as PI
|
||||
|
||||
|
||||
class Figura(ABC):
|
||||
@abstractmethod
|
||||
def oblicz_pole(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def typ_figury(self):
|
||||
pass
|
||||
|
||||
def print(self):
|
||||
print(" Figura : ", self.typ_figury(), " , Pole : ", self.oblicz_pole())
|
||||
|
||||
def __copy__(self):
|
||||
cls = self.__class__
|
||||
result = cls.__new__(cls)
|
||||
result.__dict__.update(self.__dict__)
|
||||
return result
|
||||
|
||||
|
||||
class Kwadrat(Figura):
|
||||
def __init__(self, a: int | float):
|
||||
if isinstance(a, int | float):
|
||||
self.a = a
|
||||
else:
|
||||
raise TypeError("Niewłaściwy typ boku")
|
||||
|
||||
def oblicz_pole(self):
|
||||
return self.a**2
|
||||
|
||||
def typ_figury(self):
|
||||
return " Kwadrat "
|
||||
|
||||
|
||||
class Kolo(Figura):
|
||||
def __init__(self, r: int | float) -> None:
|
||||
if isinstance(r, int | float):
|
||||
self.r = r
|
||||
else:
|
||||
raise TypeError("Koło musi mieć r typu liczba !!")
|
||||
|
||||
def oblicz_pole(self) -> float:
|
||||
return 2 * PI * self.r
|
||||
|
||||
def typ_figury(self):
|
||||
return " Koło "
|
||||
|
||||
|
||||
class Trojkat(Figura):
|
||||
def __init__(self, a: int | float, h: int | float):
|
||||
if isinstance(a, int | float) and isinstance(h, int | float):
|
||||
self.a = a
|
||||
self.h = h
|
||||
else:
|
||||
raise TypeError("Trojkat ma zle typy na wejsciu :((((")
|
||||
|
||||
def oblicz_pole(self) -> float:
|
||||
return (self.a * self.h) / 2
|
||||
|
||||
def typ_figury(self):
|
||||
return " Trojkat "
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
kwadrat = Kwadrat(3)
|
||||
kolo = Kolo(2)
|
||||
trojkat = Trojkat(2, 5)
|
||||
trojkat2 = trojkat.__copy__()
|
||||
except TypeError as e:
|
||||
print(f"Bład podczas tworzenia figur: {e}")
|
||||
except Exception as e:
|
||||
print(f"Nieznany błąd poczas tworzenia figur: {e}")
|
||||
|
||||
kwadrat.print()
|
||||
kolo.print()
|
||||
trojkat.print()
|
||||
trojkat2.print()
|
||||
68
uczelnia/2_semestr/python/laby/8/osoba.py
Normal file
68
uczelnia/2_semestr/python/laby/8/osoba.py
Normal file
@@ -0,0 +1,68 @@
|
||||
class Osoba:
|
||||
ilosc_osob: int = 0
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
pesel: str,
|
||||
imie: str,
|
||||
nazwisko: str,
|
||||
wzrost: float = 0.0,
|
||||
waga: float = 0.0,
|
||||
) -> None:
|
||||
self.__pesel = pesel
|
||||
self.__imie = imie
|
||||
self.__nazwisko = nazwisko
|
||||
self.__wzrost = wzrost
|
||||
self.__waga = waga
|
||||
Osoba.ilosc_osob += 1
|
||||
|
||||
@property
|
||||
def pesel(self) -> str:
|
||||
return self.__pesel
|
||||
|
||||
@property
|
||||
def imie(self) -> str:
|
||||
return self.__imie
|
||||
|
||||
@property
|
||||
def nazwisko(self) -> str:
|
||||
return self.__nazwisko
|
||||
|
||||
@property
|
||||
def wzrost(self) -> float:
|
||||
return self.__wzrost
|
||||
|
||||
@wzrost.setter
|
||||
def wzrost(self, nowy_wzrost: float) -> None:
|
||||
if nowy_wzrost <= 0:
|
||||
self.__wzrost = 0
|
||||
return
|
||||
self.__wzrost = nowy_wzrost
|
||||
|
||||
@property
|
||||
def waga(self) -> float:
|
||||
return self.__waga
|
||||
|
||||
@waga.setter
|
||||
def waga(self, nowa_waga: float) -> None:
|
||||
if nowa_waga <= 0:
|
||||
self.__waga = 0
|
||||
return
|
||||
self.__waga = nowa_waga
|
||||
|
||||
@property
|
||||
def data_urodzenia(self) -> str:
|
||||
return self.__pesel[:6]
|
||||
|
||||
def __del__(self):
|
||||
Osoba.ilosc_osob -= 1
|
||||
del self
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return int(self.__pesel)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.__pesel}, {self.__imie}, {self.__nazwisko}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"Osoba(pesel={self.__pesel}, imie={self.__imie}, nazwisko={self.__nazwisko}, wzrost={self.__wzrost}, waga={self.__waga})"
|
||||
45
uczelnia/2_semestr/python/laby/8/pracownik.py
Normal file
45
uczelnia/2_semestr/python/laby/8/pracownik.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from osoba import Osoba
|
||||
|
||||
|
||||
class Pracownik(Osoba):
|
||||
def __init__(
|
||||
self,
|
||||
pesel: str,
|
||||
imie: str,
|
||||
nazwisko: str,
|
||||
miejsce_zatrudnienia: str,
|
||||
wzrost: float = 0.0,
|
||||
waga: float = 0.0,
|
||||
pensja: float = 0.0,
|
||||
) -> None:
|
||||
super().__init__(pesel, imie, nazwisko, wzrost, waga)
|
||||
self.__miejsce_zatrudnienia = miejsce_zatrudnienia
|
||||
self.__pensja = pensja
|
||||
|
||||
@property
|
||||
def miejsce_zatrudnienia(self) -> str:
|
||||
return self.__miejsce_zatrudnienia
|
||||
|
||||
@miejsce_zatrudnienia.setter
|
||||
def miejsce_zatrudnienia(self, nowe_miejsce: str):
|
||||
if nowe_miejsce:
|
||||
self.__miejsce_zatrudnienia = nowe_miejsce
|
||||
return
|
||||
nowe_miejsce = ""
|
||||
|
||||
@property
|
||||
def pensja(self) -> float:
|
||||
return self.__pensja
|
||||
|
||||
@pensja.setter
|
||||
def pensja(self, nowa_pensja: float) -> None:
|
||||
if nowa_pensja >= 0:
|
||||
self.__pensja = nowa_pensja
|
||||
return
|
||||
self.__pensja = 0
|
||||
|
||||
def __str__(self):
|
||||
return f"{super().__str__()} | Miejsce zatrudnienia: {self.__miejsce_zatrudnienia} "
|
||||
|
||||
def __repr__(self):
|
||||
return f"Pracownik(pesel={super().pesel}, imie={super().imie}, nazwisko={super().nazwisko}, miejsce_zatrudnienia={self.miejsce_zatrudnienia}, wzrost={super().wzrost}, waga={super().waga}, pensja={self.pensja})"
|
||||
Reference in New Issue
Block a user