Why cant i call the functions within the class

I just started Python OOP and i also have basically 0 knowledge of python programming but we were required to build a simple class and function and i dont understand why in one case it works and in the other it doesnt

class Digital_signal_information:
    def __init__(self, signal_power :float, noise_power :float, n_bit_mod:int):

class Line:
    def __init__(self,loss_coefficient:float, length:int):
    def Loss(self,loss):

    BPSK=Digital_signal_information(0.001, 0, 1)           
    QPSK = Digital_signal_information(0.001, 0, 2)       #basically in these 4 cases i have no problem                            
    Eight_QAM = Digital_signal_information(0.001, 0, 3)    
    Sixteen_QAM = Digital_signal_information(0.001, 0, 4) 

#but if i do

#and when i try to see if i can call a.Loss it shows nothing

As i said i really just started on OOP in python so im quite confused as to whats wrong

In the exercise we have to create the class Line where we have to use the attributes signal_power and length and we have to use a function (property) (correct me if im wrong im still getting used to the OOP vocabulary). But as i said im quite confused as to why it works in one part and doesnt in the other

>Solution :

You can use @property so that the return value of the function can be directly accessed as a.Loss.

def Loss(self):
    return self.loss_coefficient * self.length

# ...
a = Line(1.0,2)
print(a.Loss) # 2.0

Leave a Reply