Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created October 8, 2020 07:01
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 sevperez/9c8fd22fcc5a03c5c6d3e468f8e22892 to your computer and use it in GitHub Desktop.
Save sevperez/9c8fd22fcc5a03c5c6d3e468f8e22892 to your computer and use it in GitHub Desktop.
class Receipt:
def __init__(self, item, cost):
self.item = item
self.cost = cost
def receipt_msg(self):
return f"{self.item}, ${round(self.cost, 2)}"
def deliver(self):
msg = self.receipt_msg()
print(f"Printing receipt... {msg}")
class EmailReceipt(Receipt):
def __init__(self, item, cost, customer_email):
super().__init__(item, cost)
self.customer_email = customer_email
def deliver(self):
msg = self.receipt_msg()
print(f"Emailing receipt to [{self.customer_email}]... {msg}")
regular_receipt = Receipt("Subscription", 120)
regular_receipt.deliver()
# Printing receipt... Subscription, $120
paperless_receipt = EmailReceipt("Subscription", 120,
"charles@diffengine.ai")
paperless_receipt.deliver()
# Emailing receipt to [charles@diffengine.ai]... Subscription, $120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment