-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathklasy_cwiczenie.py
More file actions
53 lines (42 loc) · 1.64 KB
/
klasy_cwiczenie.py
File metadata and controls
53 lines (42 loc) · 1.64 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
'''
Ćwiczenia z klas i dziedziczenia
'''
class Person():
def __init__(self,imie,naziwsko,wiek,płeć):
self.imie = imie
self.nazwisko = naziwsko
self.wiek = wiek
self.płeć = płeć
def __str__(self):
return "Imie: " + self.imie + "\nNaziwsko: " + self.nazwisko + "\nWiek: " + str(self.wiek) + "\nPłeć: " + self.płeć
class Student(Person):
def __init__(self,imie,naziwsko,wiek,płeć,oceny = []):
self.oceny = oceny
super().__init__(imie,naziwsko,wiek,płeć)
def srednia(self):
suma = 0
for item in oceny:
suma += item
return suma/len(oceny)
def __str__(self):
s = super().__str__()
return "Stduent:\n" + s + "\nOceny: " + str(self.oceny) + "\nŚrednia: " + str(self.srednia())
class Employee(Person):
def __init__(self,imie,naziwsko,wiek,płeć,zarobki):
self.zarobki = zarobki
super().__init__(imie,naziwsko,wiek,płeć)
def __str__(self):
s = super().__str__()
return "Pracownik:\n" + s + "\nZarobki: " + str(self.zarobki)
#Tworzenie instancji klas
oceny = [5,5,4,2]
student1 = Student("Robert","Łastowski",24,"M",oceny)
pracownik1 = Employee("Tomek","Kiełbasa",26,"M",15000)
student2 = Student("Grażka","Łopata",55,"K",oceny)
#Filotrowanie listy osób ze względu na płeć
lista_osob = [student1,pracownik1,student2]
for i in filter(lambda p: p.płeć =="M", lista_osob):
print (i)
#Filotrowanie listy osób z warunkiem "czy student"
studenci = list(filter(lambda p : isinstance(p,Student),lista_osob))
print("Studenci:",studenci)