BankAccount Class
Your task is to design a
BankAccount
class which will have two main attributes, account_number
and balance
. The BankAccount
class should have the following methods:deposit(amount)
: This method should take anamount
as an argument and add it to thebalance
attribute of theBankAccount
class. The method should print the stringDeposit Successful. Current Balance: $x
wherex
is the current balance after the deposit.
withdraw(amount)
: This method should take anamount
as an argument and subtract it from thebalance
attribute of theBankAccount
class. Thewithdraw
method should not allow thebalance
to go below 0 (i.e., the account cannot go into overdraft). If a withdrawal request that would lead to an overdraft is made, the method should print the stringInsufficient balance. Withdrawal failed.
and leave the balance unchanged. If the withdrawal is successful, the method should print the stringWithdrawal Successful. Current Balance: $x
wherex
is the current balance after the withdrawal.
display_balance()
: This method should print the stringCurrent Balance: $x
wherex
is the current balance.
Input | Output |
acc = BankAccount(42114541, 777); acc.deposit(100); acc.display_balance() | Deposit Successful. Current Balance: $877
Current Balance: $877 |
Tip
Don’t forget the
self
argument in class methods.Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB