task3 #2

Merged
schmidmarco merged 40 commits from task3 into main 2026-03-13 10:11:18 +01:00
Showing only changes of commit e18a3f062f - Show all commits

View File

@ -0,0 +1,32 @@
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))