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.180 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.179 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.178 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.177 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.176 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.175 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.174 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.173 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.172 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.171 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.170 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.169 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.167 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.166 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.165 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.164 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.163 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.162 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.161 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.160 tracks/python/exercises/bank-account/example.py