Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Programování 1 pro matematiky
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Programování 1 pro matematiky
Commits
e2076ee3
Commit
e2076ee3
authored
6 months ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Objekty: Řešení příkladů
parent
fd4bfabc
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
09-objekty/trida_reseni.py
+51
-0
51 additions, 0 deletions
09-objekty/trida_reseni.py
with
51 additions
and
0 deletions
09-objekty/trida_reseni.py
0 → 100644
+
51
−
0
View file @
e2076ee3
class
Zvire
:
"""
Vytvoří zvíře s danými vlastnostmi.
"""
def
__init__
(
self
,
jmeno
,
zvuk
,
pozice
=
"
doma
"
):
self
.
jmeno
=
jmeno
self
.
zvuk
=
zvuk
self
.
pozice
=
pozice
def
slysi_na
(
self
,
jmeno
):
"""
Slyší zvíře na dané jméno?
"""
return
(
self
.
jmeno
==
jmeno
or
jmeno
==
"
potvůrka
"
)
and
self
.
pozice
==
"
doma
"
def
ozvi_se
(
self
):
"""
Vydá zvuk daného zvířete.
"""
print
(
self
.
jmeno
,
"
říká:
"
,
self
.
zvuk
)
def
__str__
(
self
):
return
self
.
jmeno
def
__repr__
(
self
):
return
f
"
Zvire(
{
self
.
jmeno
}
,
{
self
.
zvuk
}
)
"
def
__eq__
(
self
,
other
):
return
(
self
.
jmeno
==
other
.
jmeno
and
self
.
zvuk
==
other
.
zvuk
)
class
Kocka
(
Zvire
):
"""
Vytvoří kočku s danými vlastnostmi.
"""
def
__init__
(
self
,
jmeno
,
zvuk
):
Zvire
.
__init__
(
self
,
jmeno
,
zvuk
)
self
.
pocet_zivotu
=
9
def
slysi_na
(
self
,
jmeno
):
# Copak kočka slyší na jméno?
return
False
class
Pes
(
Zvire
):
"""
Vytvoří psa s danými vlastnostmi.
"""
def
__init__
(
self
,
jmeno
,
zvuk
):
Zvire
.
__init__
(
self
,
jmeno
,
zvuk
)
self
.
pocet_zvuku
=
0
def
ozvi_se
(
self
):
"""
Vydá zvuk daného zvířete.
"""
self
.
pocet_zvuku
+=
1
if
self
.
pocet_zvuku
%
2
==
0
:
print
(
self
.
jmeno
,
"
říká:
"
,
self
.
zvuk
)
else
:
print
(
self
.
jmeno
,
"
říká: vrrrrrr
"
+
"
R
"
*
self
.
pocet_zvuku
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment