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
_balance
attribute should not be directly accessible from outside the class. -
You must implement the deposit (
deposit
) and withdrawal (withdraw
) methods. -
When attempting to withdraw more than the current balance, the withdrawal should be refused and the current balance returned.
Input/Output Examples
-
Example 1: Initial balance
0
, deposit100
, withdrawal50
β Final balance50
-
Example 2: Initial balance
0
, deposit200
, withdrawal250
β Final balance200
(withdrawal refused)
Guidelines
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help