-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 14.py
More file actions
31 lines (24 loc) · 915 Bytes
/
Day 14.py
File metadata and controls
31 lines (24 loc) · 915 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
class BankAccount:
def __init__(self, balance):
self.balance = balance
def deposit(self, amount):
try:
if amount <= 0:
raise ValueError("Jumlah deposit harus lebih dari nol!")
self.balance += amount
print(f"Deposit sebesar {amount} berhasil dilakukan. Saldo sekarang: {self.balance}")
except ValueError as e:
print(e)
def withdraw(self, amount):
try:
if amount > self.balance:
raise ValueError("Saldo tidak mencukupi untuk melakukan penarikan!")
self.balance -= amount
print(f"Penarikan sebesar {amount} berhasil dilakukan.Saldo sekarang: {self.balance}")
except ValueError as e:
print(e)
my_account = BankAccount(1000)
my_account.deposit(-500)
my_account.deposit(500)
my_account.withdraw(1500)
my_account.withdraw(500)