Coding Quiz - Implementing BankAccount Class
In this coding quiz, you are tasked with implementing a BankAccount class providing simple deposit and withdrawal functionality, and completing a function called solution.
The BankAccount class should contain a private variable __balance representing the account balance, and provide methods for depositing deposit and withdrawing withdraw funds.
The solution function should create a BankAccount object, perform deposits and withdrawals as specified, and return the final balance.
class BankAccount: # Write your code here def solution(initial_balance, deposit_amount, withdraw_amount): # Write your code here return
Restrictions
-
The
_balanceattribute should not be directly accessible from outside the class. -
You must implement the deposit (
deposit) and withdrawal (withdraw) methods. -
If a withdrawal request exceeds the current balance, it should be declined, and the current balance should be returned.
Input/Output Examples
-
Example 1: Initial balance
0, deposit100, withdrawal50→ Final balance50 -
Example 2: Initial balance
0, deposit200, withdrawal250→ Final balance200(withdrawal refused)
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help