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 anamountas an argument and add it to thebalanceattribute of theBankAccountclass. The method should print the stringDeposit Successful. Current Balance: $xwherexis the current balance after the deposit.withdraw(amount): This method should take anamountas an argument and subtract it from thebalanceattribute of theBankAccountclass. Thewithdrawmethod should not allow thebalanceto 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: $xwherexis the current balance after the withdrawal.display_balance(): This method should print the stringCurrent Balance: $xwherexis the current balance.
Input | Output |
|---|---|
| Deposit Successful. 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