Exercise 4: Creating a Class for a Simple Bank Account
Exercise: Creating a Class for a Simple Bank Account
In this exercise, we will create a Python class to model a simple bank account. The class will have attributes to store the account owner’s name and balance. It will also have methods to deposit money, withdraw money, and display the account information.
- Create a class called `BankAccount`.
– The class should have an `__init__` method that takes the account owner’s name and initial balance as arguments and initializes the corresponding attributes.
– The class should have methods `deposit`, `withdraw`, and `display_info`.
- The `deposit` method should take an amount as an argument and add it to the account’s balance.
- The `withdraw` method should take an amount as an argument and subtract it from the account’s balance if there are sufficient funds. If the amount exceeds the balance, display an error message.
- The `display_info` method should print the account owner’s name and current balance.
Note: For simplicity, we are not handling edge cases like negative balances or non-numeric inputs in this exercise. The focus is on creating the basic class structure and implementing the main functionality.