27 lines
466 B
Python
27 lines
466 B
Python
from dataclasses import dataclass
|
|
|
|
@dataclass
|
|
class Student:
|
|
name: str
|
|
nr: int
|
|
sem: int
|
|
|
|
@dataclass
|
|
class Rechteck:
|
|
breite: float
|
|
hoehe: float
|
|
|
|
def flaeche(self) -> float:
|
|
return self.breite * self.hoehe
|
|
|
|
# Validierung
|
|
@dataclass
|
|
class Produkt:
|
|
name: str
|
|
preis: float
|
|
|
|
def __post_init__(self):
|
|
if not self.name:
|
|
raise ValueError("...")
|
|
if self.preis < 0:
|
|
raise ValueError("...") |