Sha256: 0eda90174eb34f7dd4a796ca7ae2e62152b7cf4d726318cdb4ee0964a9f36b15

Contents?: true

Size: 826 Bytes

Versions: 52

Compression:

Stored size: 826 Bytes

Contents

import threading


class BankAccount(object):
    def __init__(self):
        self.is_open = False
        self.balance = 0
        self.lock = threading.Lock()

    def get_balance(self):
        with self.lock:
            if self.is_open:
                return self.balance
            else:
                raise ValueError

    def open(self):
        self.is_open = True

    def deposit(self, amount):
        with self.lock:
            if self.is_open and amount > 0:
                self.balance += amount
            else:
                raise ValueError

    def withdraw(self, amount):
        with self.lock:
            if self.is_open and 0 < amount <= self.balance:
                self.balance -= amount
            else:
                raise ValueError

    def close(self):
        self.is_open = False

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.138 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.137 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.136 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.135 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.134 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.133 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.132 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.131 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.130 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.129 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.128 tracks/python/exercises/bank-account/example.py