schule:programmieruebungen_klassen
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende ÜberarbeitungNächste ÜberarbeitungBeide Seiten der Revision | ||
schule:programmieruebungen_klassen [2019-12-19 16:49] – angelegt marco.bakera | schule:programmieruebungen_klassen [2020-01-06 07:32] – [Tiere: Hunde und Katzen] verschoben marco.bakera | ||
---|---|---|---|
Zeile 40: | Zeile 40: | ||
- Erstelle drei unterschiedliche Instanzen und teste damit die Methoden. | - Erstelle drei unterschiedliche Instanzen und teste damit die Methoden. | ||
- Erstelle auf ähnliche Weise ein Klassendiagramm und den Quelltext für eine Klasse " | - Erstelle auf ähnliche Weise ein Klassendiagramm und den Quelltext für eine Klasse " | ||
+ | < | ||
+ | <iframe src=" | ||
+ | |||
+ | <!-- | ||
<file Python geometrie.py> | <file Python geometrie.py> | ||
import math | import math | ||
Zeile 59: | Zeile 63: | ||
</ | </ | ||
+ | --> | ||
+ | </ | ||
< | < | ||
Zeile 117: | Zeile 123: | ||
[[https:// | [[https:// | ||
+ | |||
+ | < | ||
+ | |||
+ | <iframe src=" | ||
+ | |||
+ | </ | ||
Zeile 253: | Zeile 265: | ||
Man als auch Woman sind von Human abgeleitet sind. | Man als auch Woman sind von Human abgeleitet sind. | ||
+ | < | ||
+ | |||
+ | <iframe src=" | ||
+ | |||
+ | |||
+ | <!-- | ||
<file python god.py> | <file python god.py> | ||
def create_man_and_woman(): | def create_man_and_woman(): | ||
Zeile 279: | Zeile 297: | ||
print(" | print(" | ||
</ | </ | ||
+ | --> | ||
+ | </ | ||
< | < | ||
Zeile 304: | Zeile 324: | ||
===== Tiere: Hunde und Katzen ===== | ===== Tiere: Hunde und Katzen ===== | ||
- | Vervollständige den Quelltext für die folgenden Klassen so, dass alle Tests durchlaufen. | + | → [[Hunde und Katzen]] |
- | + | ||
- | <file python animals.py> | + | |
- | import abc | + | |
- | + | ||
- | class Animal(abc.ABC): | + | |
- | @abc.abstractmethod | + | |
- | def make_noise(self): | + | |
- | ... | + | |
- | + | ||
- | class Dog(Animal): | + | |
- | ... | + | |
- | + | ||
- | class Cat(Animal): | + | |
- | ... | + | |
- | + | ||
- | + | ||
- | # Tests | + | |
- | d = Dog() | + | |
- | c = Cat() | + | |
- | try: | + | |
- | a = Animal() | + | |
- | except TypeError: | + | |
- | print(" | + | |
- | + | ||
- | assert isinstance(d, | + | |
- | assert isinstance(c, | + | |
- | assert isinstance(d, | + | |
- | assert isinstance(c, | + | |
- | + | ||
- | assert d.make_noise() == " | + | |
- | assert c.make_noise() == " | + | |
- | </ | + | |
- | + | ||
- | < | + | |
- | + | ||
- | import abc | + | |
- | + | ||
- | class Animal(abc.ABC): | + | |
- | @abc.abstractmethod | + | |
- | def make_noise(self): | + | |
- | ... | + | |
- | class Dog(Animal): | ||
- | def make_noise(self): | ||
- | return " | ||
- | |||
- | class Cat(Animal): | ||
- | def make_noise(self): | ||
- | return " | ||
- | |||
- | |||
- | |||
- | --></ | ||
Zeile 431: | Zeile 399: | ||
wird. | wird. | ||
+ | < | ||
+ | |||
+ | <iframe src=" | ||
+ | |||
+ | <!-- | ||
<file python ghost.py> | <file python ghost.py> | ||
class Ghost: | class Ghost: | ||
Zeile 448: | Zeile 421: | ||
assert len(red_ghosts) > 10 | assert len(red_ghosts) > 10 | ||
</ | </ | ||
+ | --> | ||
+ | </ | ||
< | < |
schule/programmieruebungen_klassen.txt · Zuletzt geändert: 2020-08-14 09:48 von marco.bakera