-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank_account.py
More file actions
35 lines (26 loc) · 939 Bytes
/
Copy pathbank_account.py
File metadata and controls
35 lines (26 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class BankAccount:
def __init__(self):
self.__balance = 0
@property
def balance(self):
return self.__balance
@balance.setter
def balance(self, new_balance):
if new_balance < 0:
raise ValueError("Balance cannot be negative")
self.__balance = new_balance
def deposit(self, amount):
if amount <= 0:
raise ValueError("Deposit amount cannot be zero or negative")
self.balance += amount
def withdraw(self, amount):
if amount <= 0:
raise ValueError("Withdraw cannot be zero or negative")
if amount > self.balance:
raise ValueError("Not enough funds..!!!")
self.balance -= amount
my_account = BankAccount()
my_account.deposit(1000)
print(f"Balance in the account is: {my_account.balance}")
my_account.withdraw(50)
print(f"Balance in the account after withdraw is: {my_account.balance}")