Skip to content
C

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

text
initial balance = 500 deposit 200 withdraw 1000 withdraw 100

Example Output

text
Balance after deposit: 700 Withdrawal failed: insufficient funds Balance after withdrawal: 600

Concepts Covered

Classes, attributes, methods, conditionals, self.

Input (stdin)

Output

Run your code to see output here...