The Anatomy Of A Python Class

class Customer:

    #global limit = -1000

    def __init__(self):
        #in a real app these values would be provided most likely by a database
        self.balance = 0
        self.limit = -1000
        self.security_check = True
        self.is_active = True

    def credit_limit(self, balance):
        #limit = -1000
        if balance < self.limit:
            return False
        else:
            return True

    def withdraw(self, amount):
        #act_balance = self.balance - amount
        self.balance -= amount
        if (self.credit_limit(self.balance) == True):
            return self.balance
        else:
            return ("Withdrawl not possible. You reached the credit limit.")

    def deposit(self, amount):
        self.balance += amount
        return self.balance



a = Customer()

b = Customer()

print(a.withdraw(500))                        #   - 500
print(a.deposit(100))                         #   - 400

print(b.withdraw(1500))                       #   Withdrawl not possible. You reached the credit limit.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.