BankingSimulator Project

BankingSimulator is a project written in Python 3 that can simulate banking practices over time. The project can be found here on my Github.

Reason for Project

The reason why I created this program was to test basic money saving practices. A year ago, I studied personal finance. I did so because at that time I knew that I was not handling my finances effectively. I spent three months learning everything from how to use basic accounts to best personal investment practices. It turned out that I enjoyed running through different methods and scenarios and I came up with a paper version of what this program is.

As I started to learn how to code in Python, I also started thinking of projects to work on. Then I came across some of my finance papers with the different scenarios laid out before me. It was then that I decided to translate the ideas from paper to a functioning program.

Process

The backbone of the project is based on one class, which is used as the user’s simulated banking information. The class is made of many methods which are all used as actions for the accounts. I then decided that I needed a few functions to aid in the method implementation. After this, the program needed a way to calculate both simple and compound interest. Otherwise, this program would not really be a banking simulator. So, I created a new file which held the two interest functions. Finally, I added a main function that acts like a user menu and switch for the user to interact with in the console.

Code Snippets

While working on this project, I came across some interesting challenges that allowed me the freedom to be creative with how I handled booleans. For example, take a look at the below code which is from the account.py Account class:

def account_bridge(self):
        """Create a 'bridge' between user's input and open/close condition of account(s)."""
        if not self.savings and not self.chequings and not self.tax_free:
            cmd_ab = input("\nYou do not have any accounts! Do you want to open one [y/n]? ")

            if cmd_ab == "y":
                self.open_account()
        else:
            self.account = True
            self.account_main()

This method creates a bridge between main() and the various class methods. The other methods will work only if the user has at least one account open. This ensures that the user can’t do an action, such as deposit or withdraw, when an account is not open. By doing this, there is less of a chance that the user will encounter errors with the program.

Another interesting little implementation is with the ValueError exception handling. This error occurs in the program when the user’s input can’t be converted to an integer or a float. This is handled with a function that returns true if the error is found, and false otherwise.

def error_check_int(item):
    """Attempts to convert item to int(item).

    Function reduces the number of instances of redundant try/except blocks.

    Args:
        item (str): String to be converted.

    Return:
        bool: True if error; else False.

    """
    try:
        int(item)
        return False
    except ValueError:
        print("ERROR: Input not valid.")
        return True

The function call is handled within the methods that convert the user’s input to an integer or a float.

Overall

This project was mainly a test of two thing: can I convert the banking simulator idea into a functioning program, and am I able to use classes and methods effectively. Feel free to let me know what you think of the program. If you have suggestions or improvements, fork the repository, make the changes, and create a pull request!

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments