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:
  1. deposit(amount): This method should take an amount as an argument and add it to the balance attribute of the BankAccount class. The method should print the string Deposit Successful. Current Balance: $x where x is the current balance after the deposit.
  1. withdraw(amount): This method should take an amount as an argument and subtract it from the balance attribute of the BankAccount class. The withdraw method should not allow the balance 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 string Insufficient balance. Withdrawal failed. and leave the balance unchanged. If the withdrawal is successful, the method should print the string Withdrawal Successful. Current Balance: $x where x is the current balance after the withdrawal.
  1. display_balance(): This method should print the string Current Balance: $x where x 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

To check your solution you need to sign in
Sign in to continue