Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BaniyanProduction:
- def __init__(self, production, sold, full=0):
- self.production = production
- self.sold = sold
- self.full = 0
- #self.profit = 0 ## if you want to use self.var you must put it here
- #def profit(self, profit): #you never defined what profit was, you would have to run BP.pofit(profit) with profit being a defined int
- def profit(self):
- this_profit = self.full+self.sold #dont need self.profit as its a local variable
- return this_profit
- def loss(self):
- this_loss = self.production-self.sold
- return this_loss
- def nothing(self):
- return "invalid" ##return statmet would be better than printing
- self_p = int(input('production:>'))
- self_s = int(input('sold:>'))
- BP = BaniyanProduction(self_p, self_s)
- ##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
- #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
- #while True: #this will run it with the same arguments over and over
- if self_p == self_s:
- print(BP.profit()) ##dont need any extra vars here as you put theim in __init__ already
- elif self_s<self_p:
- print(BP.loss())
- else:
- 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