Problem 2: Bank Account Class
Easypython
Problem Description
Create a class BankAccount with an attribute balance (starting value provided at creation). Add two methods: deposit(amount) which increases the balance, and withdraw(amount) which decreases the balance only if sufficient funds are available (otherwise, it should indicate the withdrawal failed).
Input
An initial balance, followed by a series of deposit and withdrawal amounts.
Output
The balance after each operation, and a message if a withdrawal fails due to insufficient funds.
Constraints
- All amounts are positive numbers.
Example Input
textinitial balance = 500 deposit 200 withdraw 1000 withdraw 100
Example Output
textBalance after deposit: 700 Withdrawal failed: insufficient funds Balance after withdrawal: 600
Concepts Covered
Classes, attributes, methods, conditionals, self.