circle calculation with properties
This commit is contained in:
1 parent
5a57253099
commit
f2b4dbf6de
2 files changed
+196
No files matched your search
@@ -0,0 +1,97 @@
|
|||||||
|
from math import pi, sqrt
|
||||||
|
from colorama import *
|
||||||
|
init(autoreset=True)
|
||||||
|
|
||||||
|
class Kreis:
|
||||||
|
def __init__(self):
|
||||||
|
self.__r = 0
|
||||||
|
self.__u = 0
|
||||||
|
self.__A = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def r(self):
|
||||||
|
return self.__r
|
||||||
|
@r.setter
|
||||||
|
def r(self, r):
|
||||||
|
self.__r = r
|
||||||
|
self.__u = 2 * pi * r
|
||||||
|
self.__A = pi * r**2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def u(self):
|
||||||
|
return self.__u
|
||||||
|
@u.setter
|
||||||
|
def u(self, u):
|
||||||
|
self.__u = u
|
||||||
|
self.__r = u / (2 * pi)
|
||||||
|
self.__A = pi * self.__r**2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def A(self):
|
||||||
|
return self.__A
|
||||||
|
@A.setter
|
||||||
|
def A(self, A):
|
||||||
|
self.__A = A
|
||||||
|
self.__r = sqrt(A / pi)
|
||||||
|
self.__u = 2 * pi * self.__r
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
Kreis1 = Kreis()
|
||||||
|
|
||||||
|
print("\nTest r")
|
||||||
|
Kreis1.r = 3
|
||||||
|
|
||||||
|
if Kreis1.u == 18.84955592153876:
|
||||||
|
print(Fore.GREEN + "Berechnung Umfang o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Umfang Fehler")
|
||||||
|
|
||||||
|
if Kreis1.A == 28.274333882308138:
|
||||||
|
print(Fore.GREEN + "Berechnung Flächeninhalt o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Flächeninhalt Fehler")
|
||||||
|
|
||||||
|
if Kreis1.r == 3.000000:
|
||||||
|
print(Fore.GREEN + "Berechnung Radius o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Radius Fehler")
|
||||||
|
|
||||||
|
|
||||||
|
print("\nTest A")
|
||||||
|
Kreis1.A = 28.274333882308138
|
||||||
|
|
||||||
|
if Kreis1.u == 18.84955592153876:
|
||||||
|
print(Fore.GREEN + "Berechnung Umfang o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Umfang Fehler")
|
||||||
|
|
||||||
|
if Kreis1.A == 28.274333882308138:
|
||||||
|
print(Fore.GREEN + "Berechnung Flächeninhalt o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Flächeninhalt Fehler")
|
||||||
|
|
||||||
|
if Kreis1.r == 3.000000:
|
||||||
|
print(Fore.GREEN + "Berechnung Radius o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Radius Fehler")
|
||||||
|
|
||||||
|
|
||||||
|
print("\nTest u")
|
||||||
|
Kreis1.u = 18.84955592153876
|
||||||
|
|
||||||
|
if Kreis1.u == 18.84955592153876:
|
||||||
|
print(Fore.GREEN + "Berechnung Umfang o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Umfang Fehler")
|
||||||
|
|
||||||
|
if Kreis1.A == 28.274333882308138:
|
||||||
|
print(Fore.GREEN + "Berechnung Flächeninhalt o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Flächeninhalt Fehler")
|
||||||
|
|
||||||
|
if Kreis1.r == 3.000000:
|
||||||
|
print(Fore.GREEN + "Berechnung Radius o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Radius Fehler")
|
||||||
|
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
from math import pi, sqrt
|
||||||
|
from colorama import *
|
||||||
|
init(autoreset=True)
|
||||||
|
|
||||||
|
class Kreis:
|
||||||
|
def __init__(self):
|
||||||
|
self.__r = 0
|
||||||
|
self.__u = 0
|
||||||
|
self.__A = 0
|
||||||
|
|
||||||
|
def __set_r(self, r):
|
||||||
|
self.__r = r
|
||||||
|
self.__u = 2 * pi * r
|
||||||
|
self.__A = pi * r**2
|
||||||
|
|
||||||
|
def __set_u(self, u):
|
||||||
|
self.__u = u
|
||||||
|
self.__r = u / (2 * pi)
|
||||||
|
self.__A = pi * self.__r**2
|
||||||
|
|
||||||
|
def __set_A(self, A):
|
||||||
|
self.__A = A
|
||||||
|
self.__r = sqrt(A / pi)
|
||||||
|
self.__u = 2 * pi * self.__r
|
||||||
|
|
||||||
|
def __get_u(self):
|
||||||
|
return self.__u
|
||||||
|
|
||||||
|
def __get_A(self):
|
||||||
|
return self.__A
|
||||||
|
|
||||||
|
def __get_r(self):
|
||||||
|
return self.__r
|
||||||
|
|
||||||
|
r = property(__get_r,__set_r)
|
||||||
|
u = property(__get_u,__set_u)
|
||||||
|
A = property(__get_A,__set_A)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
Kreis1 = Kreis()
|
||||||
|
|
||||||
|
print("\nTest r")
|
||||||
|
Kreis1.r = 3
|
||||||
|
|
||||||
|
if Kreis1.u == 18.84955592153876:
|
||||||
|
print(Fore.GREEN + "Berechnung Umfang o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Umfang Fehler")
|
||||||
|
|
||||||
|
if Kreis1.A == 28.274333882308138:
|
||||||
|
print(Fore.GREEN + "Berechnung Flächeninhalt o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Flächeninhalt Fehler")
|
||||||
|
|
||||||
|
if Kreis1.r == 3.000000:
|
||||||
|
print(Fore.GREEN + "Berechnung Radius o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Radius Fehler")
|
||||||
|
|
||||||
|
|
||||||
|
print("\nTest A")
|
||||||
|
Kreis1.A = 28.274333882308138
|
||||||
|
|
||||||
|
if Kreis1.u == 18.84955592153876:
|
||||||
|
print(Fore.GREEN + "Berechnung Umfang o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Umfang Fehler")
|
||||||
|
|
||||||
|
if Kreis1.A == 28.274333882308138:
|
||||||
|
print(Fore.GREEN + "Berechnung Flächeninhalt o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Flächeninhalt Fehler")
|
||||||
|
|
||||||
|
if Kreis1.r == 3.000000:
|
||||||
|
print(Fore.GREEN + "Berechnung Radius o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Radius Fehler")
|
||||||
|
|
||||||
|
|
||||||
|
print("\nTest u")
|
||||||
|
Kreis1.u = 18.84955592153876
|
||||||
|
|
||||||
|
if Kreis1.u == 18.84955592153876:
|
||||||
|
print(Fore.GREEN + "Berechnung Umfang o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Umfang Fehler")
|
||||||
|
|
||||||
|
if Kreis1.A == 28.274333882308138:
|
||||||
|
print(Fore.GREEN + "Berechnung Flächeninhalt o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Flächeninhalt Fehler")
|
||||||
|
|
||||||
|
if Kreis1.r == 3.000000:
|
||||||
|
print(Fore.GREEN + "Berechnung Radius o.k.")
|
||||||
|
else:
|
||||||
|
print(Fore.RED + "Berechnung Radius Fehler")
|
||||||
|
|
||||||
Reference in new issue
Block a user