-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception.py
31 lines (30 loc) · 889 Bytes
/
exception.py
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
class BankAccount:
def __init__(self, account_balance):
self.account_balance = account_balance
def deposit(self, depo):
try:
if depo <= 0:
raise ValueError("Error! Deposits must be nonnegative!")
else:
self.account_balance += depo
except ValueError as e:
print(f"{e}")
def withdraw(self,amnt):
try:
if amnt < 0:
raise ValueError("Error! Withdrawals must be nonnegative!")
else:
self.account_balance -= amnt
except ValueError as e:
print(f"{e}")
def __str__(self):
return f"Your account balance is ${self.account_balance}"
bank = BankAccount(500)
print(bank.account_balance)
print(bank)
bank.deposit(-1)
bank.withdraw(-50)
bank.deposit(50)
print(bank)
bank.withdraw(25)
print(bank)