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.159 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.158 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.157 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.156 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.155 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.154 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.153 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.152 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.151 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.150 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.149 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.148 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.147 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.146 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.145 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.144 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.143 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.142 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.141 tracks/python/exercises/bank-account/example.py
trackler-2.2.1.140 tracks/python/exercises/bank-account/example.py