I have written 2 pieces of code.
- login and authentication
 def register():
    db = open("database.txt","r")
    account_number= input("Enter your Account Number: ")
    pin = input("Create a 4-digit pin: ")
    pin1 = input("Confirm Pin: ")
    d = []
    f = []
    for i in db:
        a,b = i.split(", ")
        b = b.strip()
        d.append(a)
        f.append(b)
    data = dict(zip(d,f))
    print(data)
    if pin != pin1:
        print("Pins don't match, try again!")
        register()
    else:
        if len(pin) != 4:
            print("Pin is not 4-digit. Pin must be 4-digit")
            register()
        elif account_number in d:
            print("account number already exists")
            register()
        else:
            db = open("database.txt","a")
            db.write(account_number+", "+pin+", 0" "\n")
            print("Success!")
    db.close()
def access():
    db = open("database.txt", "r")
    account_number = input("Enter your account number: ")
    pin = input("Enter your pin: ")
    if not len(account_number or pin)<1:
        d = []
        f = []
        for i in db:
            a, b = i.split(", ")
            b = b.strip()
            d.append(a)
            f.append(b)
        data = dict(zip(d, f))
        try:
            if data[account_number]:
                try:
                    if pin== data[account_number]:
                        print("Login Success")
                    else:
                        print("Pin or Account Number Incorrect")
                except:
                    print("Pin or Account Number Incorrect")
            else:
                print("Account Number doesn't exist")
        except:
            print("Login error")
    else:
        print("Please Enter your login credentials")
    db.close()
def home(option = None):
    option = input("Login | Signup: ")
    if option == "Login":
        access()
    elif option == "Signup":
        register()
    else:
        print("Please choose an option")
home()
- money transactions
choice = 0
while choice != 4:
      print("\n\n**** Menu *****")
      print("1 -- balance")
      print("2 == deposit")
      print("3 == withdraw")
      print("4 == cancel\n")
      choice=int(input("\nEnter your option:\n"))
      if choice==1:
             print("Balance = ", +balance)
      elif choice==2:
           dep=int(input("Enter your deposit: "))
           balance+=dep
           print("\n deposited amount: " , +dep)
           print("balance = ", +balance)
      elif choice==3:
           wit=int(input("Enter the amount to withdraw: "))
           balance -= wit
           print("\n withdrawn amount: " , +wit)
           print("balance =", +balance)
      elif choice ==4:
           print('Session ended,goodbye.')
      else:
           print("Invalid Entry")
The first code stores an account number and pin in the database. The balance should be 0 automatically for a new account. What can I do to automatically set the balance to 0 and store it in the database?
What should I do to only allow numerical values?
How can I connect the second code to the database in the first code?
 
    