Skip to content

Instantly share code, notes, and snippets.

@berinhard
Last active March 22, 2019 19:14
Show Gist options
  • Save berinhard/e88269e696bd664d290e117308c536a0 to your computer and use it in GitHub Desktop.
Save berinhard/e88269e696bd664d290e117308c536a0 to your computer and use it in GitHub Desktop.
Paperboy 002
class Wallet:
def __init__(self, money):
self.money = money
def subtract(self, amount):
self.money -= amount
def add(self, amount):
self.money += amount
class Customer:
def __init__(self, name, wallet):
self.name = name
self.wallet = wallet
def pay_for_something(self, payment):
if self.wallet:
if self.wallet.money >= payment:
self.wallet.subtract(payment)
return payment
return 0
class Paperboy:
def __init__(self, num_of_papers, newspaper_price):
self.num_of_papers = num_of_papers
self.newspaper_price = newspaper_price
def deliver_paper(self, customer):
self.num_of_papers -= 1
payment = customer.pay_for_something(self.newspaper_price)
if payment == self.newspaper_price:
print("Thanks!")
else:
print("Show me the money!!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment