Guidelines

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.

Code Format
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, deposit 100, withdrawal 50 β†’ Final balance 50

  • Example 2: Initial balance 0, deposit 200, withdrawal 250 β†’ Final balance 200 (withdrawal refused)

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help