I aim to write a class who can be used to calculate all the properties of a device.
import numpy as np
class pythagoras:
def __init__(self, a=None, b=None, c=None):
self.a = a
self.b = b
self.c = c
if(a == None):
assert(b != None)
assert(c != None)
self.a = np.sqrt(c**2 - b**2)
elif(b == None):
assert(a != None)
assert(c != None)
self.b = np.sqrt(c**2 - a**2)
elif(c == None):
assert(a != None)
assert(b != None)
self.c = np.sqrt(a**2 + b**2)
else:
assert (a**2 + b**2 == c**2), "The values are incompatible."
example1 = pythagoras(a=3, b=4)
print(example.c)
# 5
example2 = pythagoras(a=3, c=5)
print(example2.b)
# 4
example3 = pythagoras(b=4, c=5)
print(example3.a)
# 3
So my question is about simplifying this example: Is there a simpler way to implement this kind of problem? For more complex examples it gets quickly rather complex and unmanageable.
Application
The final goal is to have a class with all device properties such as:
class crystal:
absorption
refractive_index
transmission
reflection
heat_conductivity
heat_resistance
Here one can imagine that these properties depend on each other and according to my knowledge of properties, I can infer the rest of the properties.
I am graceful for any remarks about writing better code. Even though I learned and read literature about object-oriented coding, I am inexperienced in writing such.