Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_alx_pcz
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
kurs_alx_pcz
Commits
640c3c42
Commit
640c3c42
authored
Dec 01, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dziedziczenie - init
parent
98be1b10
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
klasy3.py
dzien7/klasy_wprowadzenie/klasy3.py
+21
-3
No files found.
dzien7/klasy_wprowadzenie/klasy3.py
View file @
640c3c42
...
...
@@ -15,7 +15,14 @@ class Osoba:
class
Student
(
Osoba
):
pass
def
__init__
(
self
,
imie
,
nazwisko
,
wiek
,
rok
,
kierunek
):
# Podczas inicjowania obiektu Student powinniśmy wywołać init z klasy Osoba i przekazać do niego wymagane parametry.
super
()
.
__init__
(
imie
,
nazwisko
,
wiek
)
self
.
rok
=
rok
self
.
kierunek
=
kierunek
def
srednia_ocen
(
self
):
return
4.5
class
Sklep
:
...
...
@@ -39,9 +46,20 @@ class Sklep:
osoba
=
Osoba
(
'Ala'
,
'Kowalska'
,
40
)
student
=
Student
(
'Bartek'
,
'Nowakowski'
,
20
)
student
=
Student
(
'Bartek'
,
'Nowakowski'
,
20
,
1
,
'medycyna'
)
print
(
'osoba:'
,
osoba
,
'typu'
,
type
(
osoba
))
print
(
'student:'
,
student
,
type
(
student
))
# Zarówno obiekt osoba, jak i student, mają te atrybuty, które były zdefiniowane w klasie Osoba.
# Tylko obiekt typu Student posiada atrybuty dodane w klasie Student.
print
(
'dane osoby:'
,
osoba
.
imie
,
osoba
.
nazwisko
)
#ERR print('dane osoby:', osoba.imie, osoba.nazwisko, osoba.kierunek)
print
(
'dane studenta:'
,
student
.
imie
,
student
.
nazwisko
,
student
.
kierunek
)
# Tylko obiekty klasy Student posiadają dodatkową metodę srednia_ocen
#ERR print('średnia ocen osoby:', osoba.srednia_ocen())
print
(
'średnia ocen studenta:'
,
student
.
srednia_ocen
())
print
()
osoba
.
przedstaw_sie
()
student
.
przedstaw_sie
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment