raspithek
5 months ago
2 changed files with 37 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||
from math import pi as pi |
|||
|
|||
|
|||
class Kreis: |
|||
def __init__(self, radius): |
|||
self.radius = radius |
|||
|
|||
def durchmesser(self): |
|||
return self.radius * 2 |
|||
|
|||
def umfang(self): |
|||
return self.durchmesser() * pi |
|||
|
|||
def flaeche(self): |
|||
return self.radius** 2 * pi |
|||
|
|||
|
@ -0,0 +1,20 @@ |
|||
from math import pi as pi |
|||
|
|||
|
|||
class Kreis_gettattr: |
|||
def __init__(self, radius): |
|||
self.radius = radius |
|||
self.operators ={ |
|||
'durchmesser': lambda x: self.radius * 2 |
|||
'umfang': lambda x: self.durchmesser * pi |
|||
'flaeche': lambda: x: self.radius**2 *pi |
|||
} |
|||
|
|||
def __getattr(self, name): |
|||
if name not in self.operators: |
|||
raise TypeError(f'unbekannte Operation {name}') |
|||
|
|||
return { |
|||
} [name] |
|||
|
|||
|
Loading…
Reference in new issue