Created
          March 21, 2019 19:53 
        
      - 
      
 - 
        
Save berinhard/24d1087b44867219b78ebb4207a33508 to your computer and use it in GitHub Desktop.  
    Paperboy 001
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | |
| 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 | |
| wallet = customer.wallet | |
| if wallet.money >= self.newspaper_price: | |
| wallet.money.subtract(self.newspaper_price) | |
| print("Thanks!") | |
| else: | |
| print("Show me the money!!!") | |
| ##### USAGE | |
| paperboy = Paperboy(100, newspaper_price=10) | |
| customer = Customer("Sandro", Wallet(100)) | |
| paperboy.deliver_paper(customer) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment