Dateien hochladen nach „gettattr“
Kreis.py und Krei_gettattr.py
This commit is contained in:
17
gettattr/Kreis.py
Normal file
17
gettattr/Kreis.py
Normal file
@@ -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
|
||||
|
||||
|
20
gettattr/Kreis_gettattr.py
Normal file
20
gettattr/Kreis_gettattr.py
Normal file
@@ -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]
|
||||
|
||||
|
Reference in New Issue
Block a user