Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/review/bank-account-2.py
13399 views
1
import threading
2
3
4
class BankAccount:
5
def __init__(self):
6
self.is_open = False
7
self.balance = None
8
self.lock = threading.Lock()
9
10
def get_balance(self):
11
with self.lock:
12
if not self.is_open:
13
raise ValueError('account not open')
14
return self.balance
15
16
def open(self):
17
with self.lock:
18
if self.is_open:
19
raise ValueError('account already open')
20
self.is_open = True
21
self.balance = 0
22
23
def deposit(self, amount):
24
with self.lock:
25
if not self.is_open:
26
raise ValueError('account not open')
27
if amount <= 0:
28
raise ValueError('amount must be greater than 0')
29
self.balance += amount
30
31
def withdraw(self, amount):
32
with self.lock:
33
if not self.is_open:
34
raise ValueError('account not open')
35
if amount <= 0:
36
raise ValueError('amount must be greater than 0')
37
if amount > self.balance:
38
raise ValueError('amount must be less than balance')
39
self.balance -= amount
40
41
def close(self):
42
with self.lock:
43
if not self.is_open:
44
raise ValueError('account not open')
45
self.is_open = False
46