It would be useful to show us small sample of the text file. And also the code where you actually read and use the class you have defined. Note that what you show right now is the class definition. You need to create an instance of the class (i.e. instantiate particular object of that class).
As to the class definition it's more or less correct. The problem that I see is the if condition in the assessment method. Unless self.DHB is equal to 4.5 you will get an error because
I am going to show you something more advanced. Because DIB is calculated property, it's better it to be sort of read-only (i.e. user will not be able to alter it.
As to the class definition it's more or less correct. The problem that I see is the if condition in the assessment method. Unless self.DHB is equal to 4.5 you will get an error because
rate
will not be defined when you try to use it on line 11. Also I don't think the logic is correct all together. if I understand your requirements you want to calculate DIB property always, not only when DHB == 4.5, right?I am going to show you something more advanced. Because DIB is calculated property, it's better it to be sort of read-only (i.e. user will not be able to alter it.
class Tree: def __init__(self, block, plot, species, dhb): self.block = block self.plot = plot self.species = species self.dhb = dhb @property def dib(self): return self.dhb/1.09 def report(self, report): return 'Report {}\nBlock: {}\nPlot: {}\nSpecies: {}\nDBH: {:0.3f}\nDIB: {:0.3f}'.format(report, self.block, self.plot, self.species, self.dhb, self.dib) #example how to instanciate object of class Tree #ignore numbers if they don't make business sense tree = Tree(block=1, plot=5, species=7, dhb=200) print(tree.report(1))
Output:Report 1
Block: 1
Plot: 5
Species: 7
DBH: 200.000
DIB: 183.486
>>>
I changed variable names to be compliant with PEP8 style guide. also Tree.report() method is just an example. you can take it from here and play a bit with it
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs