It is saying TypeError on line12 of createAccount(). I passed the balance variable which is float type and thought that the string formatting would convert it into float with 2 decimal places. Not sure why I am getting TypeError
from datetime import datetime
def menu():
    selection = int(input("Enter 1 to create and account:\nEnter 2 to deposit:\nEnter 3 to withdraw\nEnter 4 to quit: "))
    return selection
def createAccount():
    name = input("Enter customer name: ")
    filename = '{}.txt'.format(name)
    balance = float(input("Enter the initial deposit amount: "))
    with open(filename,'w') as balance:
        print('The balance is ${:.2f}'.format(balance))
        balance.write('{:.2f}\n'.format(balance))
    with open('log.txt','a') as log:
        timestamp = datetime.now().strftime("%d.%b %Y %H:%M:%S")
        log.write('{},customer:{}\n'.format(timestamp,name))
        log.write('transactiontype:deposit:amt:{.2f\n}'.format(balance))
def deposit():
    name = input("Enter customer name: ")
    filename = '{}.txt'.format(name)
    deposit = float(input("Enter the deposit amount: "))
    with open(filename,'r') as balance:
        current_balance = balance.readline()
        number = current_balance.rstrip()
        new_balance = float(number) + deposit
        print('Your new balance is ${:.2f}'.format(new_balance))
    with open(filename,'w') as balance:
        balance.write('{:.2f\n}'.format(new_balance))
    with open('log.txt','a') as log:
        timestamp = datetime.now().strftime("%d.%b %Y %H:%M:%S")
        log.write('{},customer:{}\n'.format(timestamp,name))
        log.write('transactiontype:deposit:amt:{.2f\n}'.format(deposit))
def withdraw():
    name = input("Enter customer name: ")
    filename = '{}.txt'.format(name)
    withdraw = float(input("Enter the withdrawal amount: "))
    with open(filename,'r') as balance:
        current_balance = balance.readline()
        number = current_balance.rstrip()
        new_balance = float(number) - withdraw
        print('Your new balance is ${:.2f}'.format(new_balance))
    with open(filename,'w') as balance:
        balance.write('{:.2f\n}'.format(new_balance))
    with open('log.txt','a') as log:
        timestamp = datetime.now().strftime("%d.%b %Y %H:%M:%S")
        log.write('{},customer:{}\n'.format(timestamp,name))
        log.write('transactiontype:withdraw:amt:{.2f\n)'.format(withdraw))
selection = None
while selection != 4:
    selection = menu()
    if selection == 1:
        createAccount()
    elif selection == 2:
        deposit()
    elif selection == 3:
        withdraw()
    print()
When running the code: Press 1 to create account Enter the username Enter initial deposit Then the error kicks in.

\ninside of format specifiersopen()on the same line, btw.open('1') as f, open('2') as f2