Compare commits
No commits in common. "e18a3f062fa0dc6eafd73507b4ce3aa5749a13d2" and "81dc543bf5e09559c4f86f35e7c85d70888c5d88" have entirely different histories.
e18a3f062f
...
81dc543bf5
@ -1,32 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class Animal(ABC):
|
||||
@abstractmethod
|
||||
def speak(slef) -> str:
|
||||
return "..."
|
||||
|
||||
def chorus(self, n: int) -> str:
|
||||
# Wiederhole den Laut n-mal als eine Zeile"
|
||||
if n <= 0:
|
||||
raise ValueError("n muss positiv sein")
|
||||
return " ".join(self.speak() for _ in range(n))
|
||||
|
||||
|
||||
class Dog(Animal):
|
||||
def speak(self) -> str:
|
||||
return "wuff"
|
||||
|
||||
|
||||
class Cat(Animal):
|
||||
def speak(self) -> str:
|
||||
return "miau"
|
||||
|
||||
|
||||
class Cow(Animal):
|
||||
def speak(self) -> str:
|
||||
return "muh"
|
||||
|
||||
|
||||
cow = Cow()
|
||||
print(cow.chorus(3))
|
||||
@ -1,17 +0,0 @@
|
||||
class A:
|
||||
pass
|
||||
|
||||
|
||||
class B(A):
|
||||
pass
|
||||
|
||||
|
||||
class C(A):
|
||||
pass
|
||||
|
||||
|
||||
class D(B, C):
|
||||
pass
|
||||
|
||||
|
||||
print(D.mro())
|
||||
@ -1,21 +0,0 @@
|
||||
class Dog:
|
||||
def speak(self) -> str:
|
||||
return "wuff"
|
||||
|
||||
|
||||
class Cat:
|
||||
def speak(self) -> str:
|
||||
return "miau"
|
||||
|
||||
|
||||
class Robot:
|
||||
def speak(self) -> str:
|
||||
return "bip bup"
|
||||
|
||||
|
||||
def chorus(animals) -> list:
|
||||
for a in animals:
|
||||
print(a.speak())
|
||||
|
||||
|
||||
chorus([Dog(), Cat(), Robot()])
|
||||
@ -1,27 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class Storage(ABC):
|
||||
@abstractmethod
|
||||
def save(self, key: str, value: str) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def load(self, key: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class MemoryStorage(Storage):
|
||||
def __init__(self) -> None:
|
||||
self.storage = {}
|
||||
|
||||
def save(self, key: str, value: str) -> None:
|
||||
self.storage[key] = value
|
||||
|
||||
def load(self, key):
|
||||
return self.storage[key]
|
||||
|
||||
|
||||
s = MemoryStorage()
|
||||
s.save("randomkey", "My Value")
|
||||
print(s.load("randomkey"))
|
||||
Loading…
x
Reference in New Issue
Block a user