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