This is a basic Python project that demonstrates object-oriented programming (OOP) by implementing a BankAccount class. The class allows for creating accounts, depositing money, withdrawing money, and checking the account balance.
The BankAccount class supports the following operations:
- Create Account: Initialize a new account with an owner's name and an optional starting balance (defaults to 0).
- Deposit: Add a positive amount to the account balance.
- Withdraw: Subtract an amount from the balance. This action is only successful if the amount is positive and does not exceed the current balance.
- Check Balance: Print the account owner and current balance using a human-readable string representation.
bank.py: Contains theBankAccountclass definition, including its attributes (owner,balance) and methods (deposit,withdraw,__str__).main.py: A simple script that demonstrates how to import, create, and use an instance of theBankAccountclass.
- Python 3.x
To run the demonstration script, execute main.py from your terminal:
python main.py