-
Notifications
You must be signed in to change notification settings - Fork 0
commit of homework no. 9 - classes and inheritance #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| class band_member: | ||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
| def play(self): | ||
| print(f'{self.name} plays on {self.instrument}') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Čo ak |
||
|
|
||
|
|
||
| class guitarist(band_member): | ||
Rebarbora6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def play(self, number_of_strings): | ||
| self.number_of_strings = number_of_strings | ||
| if self.number_of_strings >= 4 and self.number_of_strings < 6: | ||
| self.instrument = 'bass guitar' | ||
| elif self.number_of_strings >= 6: | ||
| self.instrument = 'solo guitar' | ||
| super().play() | ||
|
|
||
|
|
||
| class singer(band_member): | ||
| def play(self): | ||
| print(f'{self.name} sings') | ||
|
|
||
|
|
||
| class drummer(band_member): | ||
| instrument = 'drums' | ||
Rebarbora6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def __init__(self, name): | ||
| self.number_of_sticks = 2 | ||
| super().__init__(name) | ||
|
|
||
| def throw_a_stick(self): | ||
| self.number_of_sticks += 1 | ||
|
|
||
| def number_of_throwen_sticks(self): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Táto celá metóda mi nejak nedáva zmysel, okrem toho posledného výpisu na konci. V prvom kroku máš |
||
| if self.throw_a_stick(): | ||
| self.number_of_sticks += 2 | ||
| print(f'{self.name} allready threw {self.number_of_sticks} into the crowd.') | ||
|
|
||
|
|
||
| Tom = singer('Tom') | ||
Rebarbora6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Jan = guitarist('Jan') | ||
| Jan.number_of_strings = 4 | ||
|
|
||
| Vojta = guitarist('Vojta') | ||
| Vojta.number_of_strings = 7 | ||
|
|
||
| Filip = guitarist('Filip') | ||
| Filip.number_of_strings = 6 | ||
|
|
||
| Martin = drummer('Martin') | ||
| for _ in range(3): | ||
| Martin.throw_a_stick() | ||
| Martin.number_of_throwen_sticks() | ||
|
|
||
|
|
||
| guitarists = [Jan, Vojta, Filip] | ||
| members = [Martin, Tom] | ||
|
|
||
| for guitarist in guitarists: | ||
| guitarist.play(guitarist.number_of_strings) | ||
|
|
||
| for member in members: | ||
| member.play() | ||
Uh oh!
There was an error while loading. Please reload this page.