Skip to content

Instantly share code, notes, and snippets.

@shreezan123
Created October 4, 2018 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shreezan123/8378a46ea3464a6101984fac31a34099 to your computer and use it in GitHub Desktop.
Save shreezan123/8378a46ea3464a6101984fac31a34099 to your computer and use it in GitHub Desktop.
class FoodCalculator:
current_price = 0
def __init__(self):
pass
def add_item(self,value):
self.current_price = value #assign to instance variable
def get_tax(self,tax_rate):
return self.current_price*(tax_rate*0.01)
def get_tip(self,taxP,tipP):
after_tax = self.current_price+(0.01*taxP*self.current_price)
return ((float(tipP)/float(100))*after_tax)
def get_total_cost(self,taxP,tipP):
after_tax = self.current_price+(0.01*taxP*self.current_price)
after_tip = after_tax+(0.01*tipP*after_tax)
return after_tip
fc = FoodCalculator()
fc.add_item(100)
print fc.get_tax(10)
print fc.get_tip(10,10)
print fc.get_total_cost(10,10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment