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-1.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
if self.is_open:
18
raise ValueError('account already open')
19
self.is_open = True
20
self.balance = 0
21
22
def deposit(self, amount):
23
with self.lock:
24
if not self.is_open:
25
raise ValueError('account not open')
26
if amount <= 0:
27
raise ValueError('amount must be greater than 0')
28
self.balance += amount
29
30
def withdraw(self, amount):
31
with self.lock:
32
if not self.is_open:
33
raise ValueError('account not open')
34
if amount <= 0:
35
raise ValueError('amount must be greater than 0')
36
if amount > self.balance:
37
raise ValueError('amount must be less than balance')
38
self.balance -= amount
39
40
def close(self):
41
if not self.is_open:
42
raise ValueError('account not open')
43
self.is_open = False
44