Advertisement
AceScottie

Untitled

Jul 28th, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. class BaniyanProduction:
  2.     def __init__(self, production, sold, full=0):
  3.         self.production = production
  4.         self.sold = sold
  5.         self.full = 0
  6.         #self.profit = 0 ## if you want to use self.var you must put it here
  7.        
  8.     #def profit(self, profit): #you never defined what profit was, you would have to run BP.pofit(profit) with profit being a defined int
  9.     def profit(self):
  10.         this_profit = self.full+self.sold #dont need self.profit as its a local variable
  11.         return this_profit
  12.        
  13.     def loss(self):
  14.         this_loss = self.production-self.sold
  15.         return this_loss
  16.        
  17.     def nothing(self):
  18.         return "invalid" ##return statmet would be better than printing
  19.        
  20. self_p = int(input('production:>'))
  21. self_s = int(input('sold:>'))
  22. BP = BaniyanProduction(self_p, self_s)
  23. ##notice i do not need to specify what full should be as you already defaulted it to 0, however i can overwrite it if needed
  24. #now the BP class has set self.production and self.sold to self_p and self_s and will stay like that unless you modify them in the class
  25.  
  26.  
  27. #while True: #this will run it with the same arguments over and over
  28. if self_p == self_s:
  29.     print(BP.profit()) ##dont need any extra vars here as you put theim in __init__ already
  30. elif self_s<self_p:
  31.     print(BP.loss())
  32. else:
  33.     print(BP.nothing()) ##this is why we returned the string. Not needed but makes it cleaner.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement