0

I am new to python and may have been overly optimistic about the first project I want to tackle. I want to create a program that will help me allocate my checks(I have a banking app this is just for fun lol). I also want this to be a continuous program so it will check to see if there is a 'SavedData.txt' file and if there is it will present all the starting balances in 3 accounts from the last time it was used. Then continue to ask questions to allocate into said accounts from the new check. However, if the file doesn't exist I want it to create it, ask questions and then save the inputs to be called upon the next time it is run.

Here's what I have:

'If the file does not exist ask this prompt'
        month = input("Please enter month: ")
        day = input("Please enter the day: ")
        year = input("Please enter the year: ")
        initial_checking = int((input("What is your initial checking account balance?: ")))
        initial_savings = int((input("What is your initial savings account balance?: ")))
        initial_fun = int((input("What is your initial fun account balance?: ")))
        current_check = int((input("What is your check amount?: ")))
        save_cont = int(input("How much would you like to contribute to savings?: "))
        fun_cont = int(input("How much would you like to contribute to fun account?: "))
        current_check = int((current_check - save_cont) - fun_cont)
        print("Remaining check balance is " + str(current_check) + ".")
            def main():
                while True:
                    q = input("Would you like to put the rest in checking?(Type Y/N): ")
                    if q in "yY":
                        global initial_checking
                        global initial_savings
                        global initial_fun
                        global current_check
                        initial_checking = int(initial_checking + current_check)
                        print("Your new checking balance is " + str(initial_checking))
                        return
                    elif q in "nN":
                        print("Error! You must contribute your entire check!")
                    else:
                        print("You must enter (y/n).")

            return
            main()

After this is where I start to have issues. If the file does exist, or if the program has been run before, I want it to read the last input and display "This is your current checking account balance: $" and so on and so forth. I then want the same contribution questions to be asked and added to the current balance amount for each respective account. Doing research I have seen when doing something like 'file1 = open("SavedData.txt", "a+") ' will open and append the file. My issue is figuring out how to set up running the check for the file, opening, reading it, adding to it, or creating it then writing, and saving it.

My apologies if there is redundant information or if it looks extremely sloppy as I said I am very very new and may have been overly optimistic about doing this project. I appreciate your time and responses.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Dash
  • 1
  • 1

1 Answers1

1

As it is your first project I would suggest learning good design from the start. So try to plan out what you have to do first, what components will be needed and how will they interact (you can use sticky notes or whatever you like but have a plan before you start coding), as it will help you define classes/functions when you will be actually writing code.

So for now you nicely define the things you need to do, so do them one by one testing each step.

As of your question about file manipulation first start by writing function that opens a file and read it, as of now using with statement is good practice instead of manually opening and closing files, you can read more here and here.

Then try to write part of your code that defines what should be added to file (I'm not really sure how checks work so I can't help you here).

And when you know what you want to add create a function that will write to the file, it will be similar to reading so you can again refer to previously mentions links.

Finally if everything above is done you can try to enclose it in a loop that will constantly monitor the file. Probably the best approach would be to use already created library like watchdog but if you want to learn how filesystem works it is fine to create custom solution.

Last tip, try to avoid global variables ;P

Grekkq
  • 679
  • 6
  • 14