Problem 8 Write a class BankAccount that takes in a float initial balance initia
ID: 3902794 • Letter: P
Question
Problem 8 Write a class BankAccount that takes in a float initial balance initial_balance. The class should have two operations-a method for deposit and a method for withdraw. These two methods accept an argument amount (a float), specifying from the account. Th how much should be withdrawn or deposited ere should also be a method get_ balance, which returns the account's current balance. Depositing an amount should increase the current balance of a bank account, and withdrawing should reduce the current balance of the bank account. A user should not be allowed to withdraw more than what their current balance in their account is. If they do, an exception should be raised (raise any Exception you wish - type does not matter here). Be sure to design your class appropriately-name your attribute representing the account balance appropriately to suggest that a user of the class should not be accessing that attribute directly. C lass BonLAccount : delinst-(seif)Explanation / Answer
class BankAccount:
def __init__(self, amt):
self.balance = float(amt)
def deposit(self,amt):
self.balance = self.balance + amt
def withdraw(self,amt):
if amt > self.balance:
raise ValueError
else:
self.balance = self.balance - amt
def get_balance(self):
return self.balance;
acc = BankAccount(20.0)
acc.deposit(200)
print(acc.get_balance())
acc.withdraw(20)
print(acc.get_balance())